banner
Dave Horner's Website - Yet another perspective on things...
Home Tech Talk Unix/Linux/BSD/OSX/ETC Local rolling backups
If you appreciate the information found on this website, please drop me a line!

Who's Online

We have 28 guests online
Content View Hits : 1157195
moon and stars
How did you find my site?
 
How often do you answer random online questions?
 

Random Quote

The number of UNIX installations has grown to 10, with more expected.
--The Unix Programmer's Manual, 2nd Edition, June 1972
P1010142
P1010055
Las_Vegas_2002_172
P1010027_001

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