Results 1 to 4 of 4
Hi. I was wondering how to run a script to backup a folder nightly. My question is, If I were backing up say "website.tar.bz2"; How would I add a line ...
- 08-25-2004 #1Just Joined!
- Join Date
- Jun 2004
- Posts
- 78
creating dated filenames in a script
Hi. I was wondering how to run a script to backup a folder nightly. My question is, If I were backing up say "website.tar.bz2"; How would I add a line before the GTAR command to rename the previous file?
mv /backup/website.tar.bz2 TO "website01-01-2005.tar.bz2"
gtar -cvf /www/html/* TO /backup/website.tar.bz2
I tried mv website.tar.bz2 TO website%DATE.tar.bz2 but it didn't work.
Any help would be graciously accepted...
- 08-26-2004 #2Just Joined!
- Join Date
- Aug 2004
- Posts
- 2
Dat=`date +%m%d%y`
mv website.tar.bz2 TO website$Dat.tar.bz2
not sure if that will work but somthing to try I guess
- 08-26-2004 #3Just Joined!
- Join Date
- Jun 2004
- Location
- London, UK
- Posts
- 53
The above date statement returns "08-26-2004" (today) I hope that is what you are after. Just swap %m and %d if you prefer the other way around.Code:#!/bin/bash DAT=`date +%m-%d-%Y` if [ -f /backup/website.tar.bz2 ]; then mv -f /backup/website.tar.bz2 /backup/website.${DAT}.tar.bz2 fi tar cjf /backup/website.tar.bz2 /www/html
I also added a check function to see if there actually is a file to rename. Using gtar is not very portable, plain tar with the j option for bz2 will work on all recent linux systems.
A better way to do this may be to use ${DAT} in the file name specified for tar. You should also need some sort of "clean up" of old files so your disks don't fill up. Something like this to delete files older than 14 days.
Good luck with your scriptingCode:find /backup -name website*.tar.bz2 -ctime +14 -exec rm -f {} \;
- 10-08-2004 #4Just Joined!
- Join Date
- Jun 2004
- Posts
- 78
Thanks, I'm sorry I didnt reply to you two
I thought I did, but anyway WORKS GREAT!!


Reply With Quote
