drumhrd Posted September 15, 2009 Share Posted September 15, 2009 ok so I have no idea how to go about building this shell script. I have an external HDD on my web server. I basically want to make backups of my web root directory and store 90 days worth. I want to basically write a script to match the following PLATFORM: UBUNTU 9.04 RUNNING APACHE run everyday..I assume this is a crontab function backup directories are named "backup_".a where a = 1-90 figure out how to get the last directory saved to Since I do not want to override my backups if a server boot happens. I supposed the last directory saved will have to be a check on the date? get $a of last directory saved to $a++ cp * /var/www /media/Elements/backup_$a Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/ Share on other sites More sharing options...
trq Posted September 15, 2009 Share Posted September 15, 2009 Your probably much better of making what's known as an incremental backup. This saves spaces by only backing up data that has changed. Its easily achieved using rsync instead of a plain old copy. If you google rsync incremental backup you should find plenty of example scripts around, its pretty common practice. Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-918750 Share on other sites More sharing options...
Daniel0 Posted September 15, 2009 Share Posted September 15, 2009 If you want to do a full backup you can do something simple like this. Just make it run daily using a cron job. #!/bin/bash BACKUP_DIR=/path/to/your/backups SOURCE_DIR=/var/www mkdir -p $BACKUP_DIR TIMESTAMP=`date +%Y-%m-%d-%H%M` tar cfj $SOURCE_DIR/backup_$TIMESTAMP.tar.bz2 find $BACKUP_DIR/* -mtime +7 -exec rm -rf {} \; Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-918753 Share on other sites More sharing options...
drumhrd Posted September 15, 2009 Author Share Posted September 15, 2009 doesn't an incremental backup overwrite the changes? which would be fine as long as I have 90 days worth...if I change a file everyday over 90 days..and the error was in the 28th one..I want to be able to go back and restore that file back to day 28. I assumed incremental backups overwrite changes so I could not go back to day 28 and restore it from there..I could only restore the last day 89. Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-918758 Share on other sites More sharing options...
Daniel0 Posted September 15, 2009 Share Posted September 15, 2009 No. Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-918763 Share on other sites More sharing options...
drumhrd Posted September 15, 2009 Author Share Posted September 15, 2009 ok so the content of my backup script is as follows #!/bin/bash BACKUP_DIR=/media/Elements SOURCE_DIR=/var/www mkdir -p $BACKUP_DIR TIMESTAMP=`date +%Y-%m-%d-%H%M` tar cfj $SOURCE_DIR/backup_$TIMESTAMP.tar.gz find $BACKUP_DIR/* -mtime +7 -exec rm -rf {} \; I chmod 777 and execute I get tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information. Any Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-918766 Share on other sites More sharing options...
Daniel0 Posted September 15, 2009 Share Posted September 15, 2009 Oh yeah sorry. Change tar cfj $SOURCE_DIR/backup_$TIMESTAMP.tar.gz to tar cfj $BACKUP_DIR/backup_$TIMESTAMP.tar.gz $SOURCE_DIR That script does not do incremental backups though. Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-918767 Share on other sites More sharing options...
drumhrd Posted September 15, 2009 Author Share Posted September 15, 2009 well the script is working..but I cannot open the zip files gunzip backup_2009-09-15-1516.tar.gz gzip: backup_2009-09-15-1516.tar.gz: not in gzip format I modified the tar command slightly to exclude a /test directory I have in /var/www tar cfj $BACKUP_DIR/backup_$TIMESTAMP.tar.gz --exclude=test $SOURCE_DIR Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-919111 Share on other sites More sharing options...
Daniel0 Posted September 15, 2009 Share Posted September 15, 2009 Oops, sorry. They're in bzip2 format. Rename to *.tar.bz2 instead. Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-919113 Share on other sites More sharing options...
drumhrd Posted September 15, 2009 Author Share Posted September 15, 2009 awesome worked like a charm..just got to cron it up and I'll be good to go. thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/#findComment-919138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.