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

which seems more true?

Science is the organized skepticism in the reliability of expert opinion.
— Richard Feynman
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,...
xn = xn-1 + xn-2

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