WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Backup with Date and Time  (Read 5810 times)

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Backup with Date and Time
« on: May 20, 2011, 10:44:55 AM »
Following is a guide on how to save backups with the date and time.

Add the following to /opt/shutdown.sh

Quote
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.

Quote
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.
Many people see what is. Some people see what can be, and make a difference.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: Backup with Date and Time
« Reply #1 on: May 20, 2011, 11:15:29 AM »
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.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Backup with Date and Time
« Reply #2 on: May 20, 2011, 11:36:11 AM »
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.

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Backup with Date and Time
« Reply #3 on: May 20, 2011, 12:21:36 PM »
Quote
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.
Many people see what is. Some people see what can be, and make a difference.

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Backup with Date and Time
« Reply #4 on: May 20, 2011, 03:41:52 PM »
Quote
Also, not sure if ":" would be a valid character for filenames under all possible circumstances.

Here is a different date format

Quote
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
« Last Edit: May 20, 2011, 09:58:06 PM by Guy »
Many people see what is. Some people see what can be, and make a difference.

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Backup with Date and Time
« Reply #5 on: May 20, 2011, 03:45:06 PM »
Quote
To avoid having too many backups, lets keep a configurable number of latest backups an delete olds.

Quote
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.
« Last Edit: May 20, 2011, 09:58:43 PM by Guy »
Many people see what is. Some people see what can be, and make a difference.

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Backup with Date and Time
« Reply #6 on: May 22, 2011, 06:07:57 AM »
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
Many people see what is. Some people see what can be, and make a difference.

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: Backup with Date and Time
« Reply #7 on: May 26, 2011, 03:46:38 AM »
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!


Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Backup with Date and Time
« Reply #8 on: May 26, 2011, 10:42:05 AM »
Quote
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.
« Last Edit: May 26, 2011, 10:45:10 AM by Guy »
Many people see what is. Some people see what can be, and make a difference.

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: Backup with Date and Time
« Reply #9 on: May 26, 2011, 12:01:06 PM »
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.
« Last Edit: May 26, 2011, 12:04:11 PM by netnomad »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Backup with Date and Time
« Reply #10 on: May 26, 2011, 12:15:04 PM »
It is just a gzipped tar file.
tar tvzf mydata.tgz

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Backup with Date and Time
« Reply #11 on: May 26, 2011, 12:37:16 PM »
Quote
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
Many people see what is. Some people see what can be, and make a difference.

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: Backup with Date and Time
« Reply #12 on: May 26, 2011, 01:13:00 PM »
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.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: Backup with Date and Time
« Reply #13 on: May 26, 2011, 01:33:53 PM »
Quote
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.

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Backup with Date and Time
« Reply #14 on: May 26, 2011, 01:42:51 PM »
Quote
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?
Many people see what is. Some people see what can be, and make a difference.