Local rolling backups |
| Friday, 23 December 2005 07:13 |
|
Having a couple days worth of backup can be very useful. I like to use rdiff-backup for the entire system, but I also use multiple rolling backup scripts that send data out to remote servers as well as local storage. Below is a script that I've made for backing up mysql databases. <br/> #!/bin/bash<br/> <br/> # path to backup,make sure directory exists first (no trailing slash)<br/> backup=/path/to/backup<br/> <br/> # get dates into variables<br/> dayofweek=`date +%a`<br/> month=`date +%m`<br/> weeknumber=`date +%V`<br/> <br/> #backup database with password and username.<br/> # add -uroot -psomepassword to indicate username and password.<br/> <br/> /usr/bin/mysqldump --quote-names -A --add-drop-table | gzip > ${backup}/dbbackup${dayofweek}.sql.gz<br/> <br/> if [ "$dayofweek" = "Fri" ]; then<br/> <br/> #if you want 1 extra backup every month (12 a year), use this one<br/> cp ${backup}/dbbackup${dayofweek}.sql.gz ${backup}/dbbackup${dayofweek}.${month}.sql.gz<br/> <br/> #if you want 1 backup every week (52 per year), use this one<br/> #cp ${backup}/dbbackup${dayofweek}.sql.gz ${backup}/dbbackup.${weeknumber}.sql.gz<br/> ls -l ${backup}<br/> exit 0<br/> fi<br/> <br/> ls -l ${backup}<br/> <br/> exit<br/> The script above would simply store local copies. For remote backup you could use a command like scp or mime-construct (for sending out email). mime-construct --to user@domain --subject "backup" --file "/path/to/file" Now all you have to do is stick this script in your cron.daily folder to start backing up every night! |
| Last Updated on Monday, 30 October 2006 17:52 |

