This is a start in our adventures of exploring some automated backup solutions. We decided to go simple and homebrew for the first method and used a shell script tied to cron to run mysqldump to backup the databases and rsync to backup some critical directory trees.
--text coming soon---
#!/bin/bash
###################################################################################
##
## backup-webserver.sh
## Script to backup the webserver to remote machine
##
## Runs nightly via CRON as such:
## 00 4 * * * /root/backup-webserver.sh >> /tmp/daily_cron_backup
## every night at 4am runs and all output logged to /tmp/daily_cron_backup
##
####################################################################################
# remote user and host to serve as backup machine
# make sure you have enabled passwordless ssh login using keys
REMOTESERVER="remoteuser@remotehost"
# mysql options
MYSQLOPTIONS="--all-databases"
# setup the username and password for mysqldump
USER="root-user"
PASS="root-user-password"
# setup the dump filename based on date and substitute underscore for spaces and colons
MYSQLOUTFILE=$(echo $(date).sql | tr ' ' '_' | tr ':' '_')
# destination to backup the dump file to
MYSQLBACKUP=":/remote-dir/backups/webserver/mysql/"
# webserver directory trees to backup
RSYNCFILE1="/home/"
RSYNCFILE2="/etc/"
RSYNCFILE3="/var/"
# destination on backup device to copy to
RSYNCBACKUP1=":/remote-dir/backups/webserver/rsync/home/"
RSYNCBACKUP2=":/remote-dirbackups/webserver/rsync/etc/"
RSYNCBACKUP3=":/remote-dir/backups/webserver/rsync/var/"
# rsync options
# -a does 'rlptgoD' : recursive, links, perms (includes --executability), times, group, owner, Devices
RSYNCOPTIONS="--stats --rsh=/usr/bin/ssh -a --update --hard-links --verbose"
# run the mysqldump
mysqldump $MYSQLOPTIONS -u $USER --password=$PASS >> $MYSQLOUTFILE
# send the dump file to the backup machine
scp $MYSQLOUTFILE $REMOTESERVER$MYSQLBACKUP
# run rsync on each of the backup directory trees
rsync $RSYNCOPTIONS $RSYNCFILE1 $REMOTESERVER$RSYNCBACKUP1
rsync $RSYNCOPTIONS $RSYNCFILE2 $REMOTESERVER$RSYNCBACKUP2
rsync $RSYNCOPTIONS $RSYNCFILE3 $REMOTESERVER$RSYNCBACKUP3
Comments (0)
Mutaku.com
http://www.mutaku.com/geeklog/article.php?story=20080806204809923