Tiny Core Linux
General TC => General TC Talk => Topic started by: Guy on May 20, 2011, 01:44:55 PM
-
Following is a guide on how to save backups with the date and time.
Add the following to /opt/shutdown.sh
DATE=$(date +"%Y%m%d-%H:%M")
DATA=Data-$DATE.tgz
cp /mnt/sda1/tce/mydata.tgz /mnt/sda1/tce/$DATA
If not using sda1, change it to the correct partition.
This copies the backup file to another file with the date and time, in this format.
Data-20110520-15:31.tgz
You can change the format if you modify the commands.
If you have year, month, day, then time, in that order, it will keep the backup files in order.
Be aware, a new backup file is created every time you turn off the computer. At times you will need to delete some.
I have also put this in the wiki, but have included it here for those who may not read the wiki.
-
Interesting approach.
Actually I manually copy backups to an archivation dir and rename them by appending date.
However, using /opt/shutdown.sh has the disadvantage that only backups done at shutdown would be archived - as opposed to periodical ones.
Also, not sure if ":" would be a valid character for filenames under all possible circumstances.
-
Just a quick idea, rename existing backup with date and time when a new backup is created automatically. In this case last backup has always the same name as currently so works automatically. To avoid having too many backups, lets keep a configurable number of latest backups an delete olds.
-
However, using /opt/shutdown.sh has the disadvantage that only backups done at shutdown would be archived - as opposed to periodical ones.
You could run this from the terminal at any time.
Or even automate it to run at certain time intervals.
For many home users, every time they turn their computer off, would be more often than necessary.
It is a concept that users can modify as desired.
-
Also, not sure if ":" would be a valid character for filenames under all possible circumstances.
Here is a different date format
DATE=$(date +"%Y.%m.%d-%H.%M")
DATA=Data-$DATE.tgz
cp /mnt/sda1/tce/mydata.tgz /mnt/sda1/tce/$DATA
it looks like this
Data-2011.05.21-07.51.tgz
-
To avoid having too many backups, lets keep a configurable number of latest backups an delete olds.
ls -1t /mnt/sda1/tce/Data-*tgz | tail -1 | xargs /bin/rm -f
DATE=$(date +"%Y.%m.%d-%H.%M")
DATA=Data-$DATE.tgz
cp /mnt/sda1/tce/mydata.tgz /mnt/sda1/tce/$DATA
After you have reached the number of backups that you want, you can add another line, as above. This will delete the oldest backup, and create a new one.
This is just an idea, users can modify this how they like.
-
I have now saved this in a file, so you can run it by typing the name of the file.
I have added seconds.
http://wiki.tinycorelinux.net/wiki:backup_date
-
great work!
is it possible that your script uses the LABEL of the partition, too!?
do i need to browse the fstab per script to extract the TCE destination,
then to insert it as a VARIABLE?
thank you!
-
is it possible that your script uses the LABEL of the partition, too!?
do i need to browse the fstab per script to extract the TCE destination,
then to insert it as a VARIABLE?
Updated, so it automatically gets the partition.
There are also other improvements.
It automatically deletes the old ones after a certain number have been reached.
It also works for encrypted backups.
-
hello guy,
you did a really great job!
everything works smoothly...
but there is still something i am looking for...
actually i want to extract files from mydata.tgz.bfe without starting tc or restore the whole backup.
you have to know that i run tc on different usbsticks and sometimes i improved some configuration files on one stick and i want to use just this one file on another stick...
and i don't want to go the long way like to start tc and copy the file on a shared partition and so on...
i tried on the command line:
tc@box:~$ bcrypt mydata.tgz.bfe
but i get a
tc@box:~$ Invalid encryption key for file: mydata.tgz.bfe
although i used the right password
do you see there a chance to encrypt it on the command line, on a different tc-installation or even better on a different platform that offers bcrypt and an archiver to open tgz.
thank you for your help in advance.
-
It is just a gzipped tar file.
tar tvzf mydata.tgz
-
do you see there a chance to encrypt it on the command line, on a different tc-installation or even better on a different platform that offers bcrypt and an archiver to open tgz.
http://wiki.tinycorelinux.net/wiki:encrypt_files
-
hey guy,
i use sucessfully bcrypt on the command line and i use untar quite often, too.
that's no problem at all...
the point is:
can you decrypt the mydata.tgz.bfe on the command line,
i mean the protected backup-file encrypted in the protected mode of tc!?
i guess that the protected mode script uses different steps to archive the files and encrypt them,
perhaps over pipes, that the mydata.tgz.bfe gets something like a "special encrypted, archived format"?
perhaps you can give me a hint to understand it?!?
again, i experienced that it's not just a bcrypted file in the tar-format.
perhaps i'm wrong.
thanks for your help.
-
can you decrypt the mydata.tgz.bfe on the command line,
Yes. If you examine /usr/bin/filetool.sh, you can see how it is encrypted:
KEY=$(cat /etc/sysconfig/bfe)
cat << EOD | sudo /usr/bin/bcrypt -c "$MOUNTPOINT"/"$FULLPATH"/$1 2>/dev/null
"$KEY"
"$KEY"
EOD
to decrypt:
sed 's/^/"/;s/$/"/;p' /etc/sysconfig/bfe | bcrypt mydata.tgz.bfe
For some reason, double quotes are added to the password before encrypting. I'm not sure why.
-
For some reason, double quotes are added to the password before encrypting. I'm not sure why.
It may be so people don't decrypt it using the command line.
Are you now able to decrypt it using the command line?
-
Are you now able to decrypt it using the command line?
Yes. I tested it before posting. I created an encrypted backup and then decrypted it using that command.
-
I have just updated this again, so if the "mydata=another-name" bootcode is used, it will still work.
http://wiki.tinycorelinux.net/wiki:backup_date
-
yeah it works.
i read a little bit in the manuals about sed, so i begin to understand...
so the sed command changes the ^ to " and $ to "...
that means the password in /etc/sysconfig/bfe is in the format ^password$ and for bcrypt it's needed in the format "password"!?
and afterwards sed prints the password two times to stdout !?
for this command line i need the password in a text-file.
i tried different ways like
echo "password" | bcrypt mydata.tgz.bfe
and didn't succeed...
do you see there a further approach that uses the password on the command line without the password-file?
-
If you used the password
12345678
to encrypt it (encrypted backup).
Use
"12345678"
to decrypt it (command line).
http://wiki.tinycorelinux.net/wiki:encrypt_files
-
that means the password in /etc/sysconfig/bfe is in the format ^password$
No, ^ matches the beginning of the line and $ matches the end of the line. My command just adds double quotes around the password before passing it to bcrypt.
echo \"password\"|sed p|bcrypt mydata.tgz.bfe
will also work, but if your password is in a variable, you need to use:
echo \""$pw"\"|sed p|bcrypt mydata.tgz.bfe
-
now i understand:
tc@box:~$ bcrypt mydata.tgz.bfe
Encryption key:
now i have to give my password in the format "password" and it encrypts fine.
thats what i was looking for, thank you friends.
hi danielibarnes,
i understand that sed is a very strong tool, that's worth to learn...