Wednesday, February 22, 2012

rsync backup script sample

#!/bin/bash
# Adapted from tridge@linuxcare.com, rsync.samba.org/examples.html
# This script does personal backups to a box using rsync over ssh.
# It does 7 day rotating incrementals.  The incrementals will go into sub
# directories named after the day of the week, and the current full backup
# goes in to a directory called ‘current’
# directory to backup
BDIR=/home/$USER
# name of the backup machine
BSERVER=your.backup.server
# excludes file contains a wildcard pattern per line of files to exclude
EXCLUDES=$HOME/path/to/excludes
# ssh options
#SSHI=’”ssh -i $BDIR/.ssh/batchkey”‘
BACKUPDIR=`date +%A`
OPTS=”–force –ignore-errors –delete-excluded –exclude-from=$EXCLUDES –delete –backup –backup-dir=$BACKUPDIR -a”
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
[ -d $HOME/emptydir ] || mkdir $HOME/emptydir
rsync –delete -a -e “ssh -i $BDIR/.ssh/batchkey” $HOME/emptydir/ $USER@$BSERVER:~/current/$BACKUPDIR/
rmdir $HOME/emptydir
# now the actual transfer
rsync $OPTS -e “ssh -i $BDIR/.ssh/batchkey” $BDIR $USER@$BSERVER:$BDIR/current
The excludes file:
*.mp3
*~
Temporary\ Internet\ Files
*.ogg
*.iso

No comments:

Post a Comment