I have been wanting a simple script to back up websites. Everything I have found usually does WAY too much, and its hit or miss if it does what I really want it to. Then I had the idea, why don’t I write a backup script and have it do only what I want it to do. I know its going to start out pretty rough, and I mean really rough, but I am going to continue to add and refine. It will also be an exercise in shell scripting beyond little the one-offs I usually am throwing together. This script is probably best for small backups that have a high activity level since it only does a full backup.
Giving credit where credit is due. I borrowed heavily from the AutoMySQLBackup script, which I use on all my servers to backup the MySQL databases. You might see striking similarities if you compare the two scripts.
I have put the script on Google code so I can manage it a bit easier. Here is where you can find it: http://code.google.com/p/jrbackup/
Currently the script does not address offsite backups so you will need to concoct something to get the backups off the server. Something along the lines of this I suspect will work:
0 1 * * * rsync -avu --del -e /backups backups@myOffSiteHost:/Backups
- Extract the compressed file to a location of your choice
- Open the file in a text editor
- Modify the configuration options at the top, do not change anything beyond the warning to stop editing unless you know what you are doing
- Check to make sure the file is executable
- Create a cron job to run the script once a day:
- Put the script in /etc/cron.daily
- 0 1 * * * jrbackup.sh
— Implemented features
- Rolling daily backups
- Rolling weekly backups
- Rolling monthly backups
- Email of results of backup
- Exclude directories in backup parent directory
— Planned features:
- Options on backup output:
- None (quiet)
- Email and logs
- Backup more than one directory
- SCP to offsite location
- Have some sort of fall-back if mail doesn’t work
- Weekly backups (optional)
- Monthly backups (optional)
- More intelligent way of designating exclude dirs, esp with multiple backup dirs
- Only report errors if there actually are errors
— Known bugs:
- None so far..
— Change log
## Ver. 0.2 ##
Weekly rolling backups are now working. Error logging was cleaned up and the debug method was given a small dose of sanity with formatting and a timestamp. Monthly backups with monthly purge implemented. Still only backs up a single directory hierarchy. The learning continues.
## Ver. 0.1 ##
Currently you point it at a parent directory and it basically creates a tarball in a specified directory. It will only (ever) do a full backup, as disk space is pretty cheap these days there is little need to even attempt incremental or differential backups. Rather than letting the script run wild and simple continue to keep creating backups, at this point it only creates 7 days worth of backups. See the section after the code for planned features.