Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup with a date stamp in Filename on Hard Disk.

Status
Not open for further replies.

salimwng

IS-IT--Management
Mar 11, 2002
134
MU
OS Platform: SCO Unix Sys/V

Hello,

Beside of doing backup on tape everyday, i would like to do the backup on Hard Disk too. I have created a batch file for doing this but however i DO NOT WANT it to be overwritten everyday. The command is

tar cvf /ibm3/bakXXXXX.tar /u/peg

/u/peg --> is the Data folder which need to be backed up.
/ibm3/bakXXXXX.tar ---> is the filename i want to put at it.

The problem is that i would like to know if there's a command which exist or a short program which can automatically assign the filename ( in the place of bakXXXXX.tar ) as per the date stamp. That is if today is 01.07.2002, the filename is bak010702.tar and tomorrow will be bak020702.tar and so on and so forth.

Could anybody help me please, i have been trying lot's of stuff but in vain.

Thank you so much
Regards.
Salim
 
Easy one - and many ways!

To get the date in the format you want use

date -u +%d%m%y
# This will give date as 070102

If you set a variable for date and then call it from the backup routine your using you should be OK.
i.e.
todaysdate=`date -u +%d%m%y`
tar cvf /ibm3/bak$todaysdate.tar /u/peg

Not too sure if it will like the bak before the variable. Try it!
 
We backup some critical file directories to the hard drive on a daily basis. In our case we backup only for a week. We back up the entire system daily on tape. The daily backups are for quick reference. In our case:

DATE=`/bin/date +%A`

cd /u/appl/filepro
tar cvf /tmp/u_${DATE}.tar ./*

This is only the first few lines, but you can get the idea. 'man date' to get the variable setup that works best for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top