Help changing backup script
At the bottom off this post is the backup script that I am using that I found off the net. What I need to do is on saturday erase the tape using mt erase then on sunday morning I will use cat to write to the tape, but is gotta check the date to get the file name. Then on the rest of the week monday / saturday I'll neet to write the incrementals. The problem is that this is way over my head and I need some guidence. I'd like to learn more about bash scripting if I had time so I am asking for help. It doesn't need to be a part of this script. Actually I don't want it to be apart. What I do need to know is how to search for a file in a directly by date or something.
I am sure someone here know what I am looking for. Also can someone show me how to remove filles older than 5 days. I'd like to keep 5 days worth and then delete anything older than that. #!/bin/sh # jason pepas's backup script - see http://jason.pepas.com # shell script tutorials: # http://www.freeos.com/guides/lsst/ # http://www.linuxnewbie.org/nhf/inte...bashscript.html # -------------------------------------------------- # set variables: # -------------------------------------------------- directoryname=`date +%Y-%m-%d`"_"`hostname`"_backup" current="current_"`hostname` fullbackuplabel="Full Backup of "`hostname`" on "`date '+%B %e, %Y'` fullbackupname=`date +%Y-%m-%d`"_full.tar.gz" fullbackuplogname=`date +%Y-%m-%d`"_full.log" incrementalbackuplabel="Incremental Backup of "`hostname`" on "`date '+%B %e, %Y'` incrementalbackupname=`date +%Y-%m-%d`"_incremental"`date +%H%M`".tar.gz" incrementalbackuplogname=`date +%Y-%m-%d`"_incremental"`date +%H%M`".log" # -------------------------------------------------- # functions: # -------------------------------------------------- fullbackup() { # create backup directory if test ! -e /backup/$directoryname; then echo "Creating /backup/$directoryname directory" mkdir /backup/$directoryname fi # create (or update) a shortcut called current to this directory echo "Updating /backup/$current pointer" rm /backup/$current ln -s /backup/$directoryname /backup/$current # keep track of creation date of full backup (used with incremental backups) echo "Updating /backup/$current/lastfullbackupdate" date>/backup/$current/lastfullbackupdate # create backup echo "Running tar..." tar --create --label "$fullbackuplabel" --files-from /backup/scripts/whattobackup --exclude-from /backup/scripts/whatnottobackup --ignore-failed-read --absolute-names --verbose --gzip --file /backup/$current/$fullbackupname > /backup/$current/$fullbackuplogname 2>&1 gzip /backup/$current/$fullbackuplogname echo "Done. Created /backup/$current/$fullbackupname" echo "To view the log, type:" echo " zcat /backup/$current/$fullbackuplogname" } incrementalbackup() { # create variable with date of last full backup lastfullbackupdatevar=`cat /backup/$current/lastfullbackupdate` # check for existence of incremental backup if test -e "/backup/$current/$incrementalbackupname"; then echo "Your last incremental backup was less than 60 seconds ago." echo "Wait a minute and try again." else # create incremental backup echo "Running tar..." tar --create --label "$incrementalbackuplabel" --files-from /backup/scripts/whattobackup --exclude-from /backup/scripts/whatnottobackup --ignore-failed-read --after-date "$lastfullbackupdatevar" --absolute-names --verbose --gzip --file /backup/$current$incrementalbackupname > /backup/$current $incrementalbackuplogname 2>&1 gzip /backup/$current/$incrementalbackuplogname echo "Done. Created /backup/$current/$incrementalbackupname" echo "To view the log, type:" echo " zcat /backup/$current/$incrementalbackuplogname" fi } # -------------------------------------------------- # main routine: # -------------------------------------------------- # first get a list of all packages installed. #dpkg --get-selections > /etc/apt/selections # clear out apt's packages #apt-get clean # now perform the backup. echo "---------- Backup Script Running... ----------" if test `date +%A` = "Sunday" && ! -e "/backup/$directoryname"; then # if it is sunday and you havent yet done a full backup, do so echo "Performing Weekly Full Backup..." fullbackup; elif test ! -e /backup/$current/*full.tar.gz; then # if there is no current fullbackup, make one echo "No Current Full Backup - Performing Full Backup Now..." fullbackup; else # otherwise, do an incremental backup echo "Performing Incremental Backup..." incrementalbackup; fi # end if statement echo "---------- Backup Script Done ----------" |
Try this page on the 'find' cmd:
http://www.tldp.org/LDP/abs/html/moreadv.html |
Hi Phatboyz,
I took a look at the direction pointed by Chrism01 and I thought is very interesting. But, resuming your needs, I understood you need to give some decisions based on the day of the week. I would recommend you to give a look into the man page for "date". It is a powerful command and is frequently used on the script you use. For you get a numeric day of the week you could use: Code:
DOW=`date +"%w"` Code:
if [ $DOW -eq 0 ]; then Code:
case $DOW in Code:
find <directory> -type f -mtime +5 -exec rm {} \; |
Thanks, Yea I started using the find command with -name to find just *.tar.gz and this seems to work fine. Yea I am going to go back and use your code for the date and stuff. I think it will be easyer to have cron run it everyday and then let the script decide when it wants to do something.
Thank you for all your help and I am sure that I am not done either. |
Quote:
|
All times are GMT -5. The time now is 10:22 AM. |