Dave Horner's Website - Yet another perspective on things...
Home Tech Talk Unix/Linux/BSD/etc Local rolling backups
30 guests
Rough Hits : 2769311
moon and stars
how did u find my site?

our entire universe; minuscule spec in gigantic multiverse which is mostly lethal.

“The future has already arrived. It's just not evenly distributed yet.”
- William Gibson

L:0 I:0 A:0

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.
# path to backup,make sure directory exists first (no trailing slash)<br/>
# get dates into variables<br/>
dayofweek=`date +%a`<br/>
month=`date +%m`<br/>
weeknumber=`date +%V`<br/>
#backup database with password and username.<br/>
# add -uroot -psomepassword to indicate username and password.<br/>
/usr/bin/mysqldump --quote-names -A --add-drop-table | gzip > ${backup}/dbbackup${dayofweek}.sql.gz<br/>
if [ "$dayofweek" = "Fri" ]; then<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/>
        #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/>
ls -l ${backup}<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