#!/bin/bash # This script does a backup of a directory to the backup server. # It is based on the following example script: # This script does personal backups to a rsync backup server. You will end up # with a 7 day rotating incremental backup. The incrementals will go # into subdirectories named after the day of the week, and the current # full backup goes into a directory called "current" # tridge@linuxcare.com # Run as root. # copyDir dir dest [CleanUp] # dir is the directory to back up. # dest is the backup set name. # if CleanUp is not empty, the last-period backup is removed. Only do this once per day. if [ $# -lt 2 ]; then echo "copyDir dir set [clean]" echo "set is daily or weekly" echo "If there is ANYTHING in the [clean] position, the previous" echo " cycle's diff dir is removed." exit fi echo Copy $1 if [ "$2" == "weekly" ]; then echo "Weekly" BSERVER=io.dhzone.com EXCLUDES=/etc/backup/exclude BACKUPDIR=Week_`date +%W` SET="${HOSTNAME%%.*}/weekly" else # "daily" echo "Daily" BSERVER=io.dhzone.com EXCLUDES=/etc/backup/exclude BACKUPDIR=`date +%A` SET="${HOSTNAME%%.*}/daily" fi # directory to backup BDIR=$1 ######################################################################## OPTS="--force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES --delete --backup --backup-dir=$BACKUPDIR -a --links " export PATH=$PATH:/bin:/usr/bin:/usr/local/bin if [ $# -ge 3 ]; then echo "Clean" # the following line clears the last weeks incremental directory [ -d /tmp/emptydir ] || mkdir /tmp/emptydir rsync --delete -a /tmp/emptydir/ $BSERVER:/backup/$SET/$BACKUPDIR/ rmdir /tmp/emptydir fi # now the actual transfer rsync $OPTS $BDIR $BSERVER:/backup/$SET