We help IT Professionals succeed at work.

Back ups

choccarlm
choccarlm asked
on
Hi, I've a written a small shell script that tar's certain directories and then moves the tar files to a backup directorie. Is it possible to add the time /date at the beginning of the tar files? I.E If the tar file is called website.tar, would it be possible using shellscript to call that file (date)20012210(&)(time)1100website.tar? I.E 200122101100website.tar. Meaning the backup was made at 11:00 on October 22nd 2001.
Comment
Watch Question

Commented:
When generating the file name do something like this:

tar cvzf backup-`date +%Y%d%m%H%M`.tar.gz

Note that the ` around "date" are backticks (above the TAB key on UK keyboards, I don't know about elsewhere).

You can put any command between then and the system will resolve the command and put the output in to the previous command.

Read the man pages for the data command to see what options you can use to format it the way you want.

Author

Commented:
How do I assign the date to a constant. I need the date set to this because the script takes a while to run and it appends files to archives, and if the time changes in between, then it will attempt to add to an archive that doesnt exist. I.E when the script starts, it will create a tar file (-cvzf) with the time set as 0900, but when it gets further down the script, and has to append, the time would have changed. Thanks
CERTIFIED EXPERT

Commented:
bash, sh, ksh% date=`date +%Y%d%m%H%M`; tar cf backup-$date.tgz
csh, tcsh% set date = `date +%Y%d%m%H%M`; tar cf backup-$date.tgz

Explore More ContentExplore courses, solutions, and other research materials related to this topic.