TroelsScript

From RdiffBackupWiki

Jump to: navigation, search

another script, used by Troels Arvin <troels@arvin.dk>

#====/bin/sh===

# This script should be run on the backup-server, i.e. the
# server storing the backup-data.
# It's assumed that ssh will be used to transport the
# data, and that unattended ssh-login has been set up,
# see http://arctic.org/~dean/rdiff-backup/unattended.html

# The script may be put in a crontab so that backup is
# done every night.

# Version 1.0 (Thu Oct 30 2003) by Troels Arvin <troels@arvin.dk>.
# Use at your own risk.

# Room for improvement:
#  - backup the remote hosts in parallel
#  - use lock-files/semaphores to prevent concurrent
#    backup of the same host
#  - different options for the different hosts

########################################################
# Configuration                                        #
########################################################

# The remote hosts that need to be backed up to this host
BACKUP_HOSTS='host1.mydomain.com host2.mydomain.com host3.mydomain.com'

# Where to store the backup data
BACKUP_DIR="/home/backup"

# What area to backup and not to backup on the remote hosts
BACKUP_PATH="/"
EXCLUDES="/tmp /var/tmp /var/log /proc /mnt/cdrom"
EXCLUDE_OPTIONS="--exclude-device-files"

# What user to login as on the remote hosts
SSH_USER='root'

# How long to keep changes. 1M = 1 month
MAXAGE="1M"

# Which program to invoke
BINARY=/usr/bin/rdiff-backup

# Some basic configuration options; see the manual
OTHER_OPTIONS="--print-statistics --no-change-dir-inc-perms"


########################################################
# Perform backup                                       #
########################################################

# Build a bunch of --exclude ... statements and construct
# a number of arguments to send to rdiff-backup.
for i in $EXCLUDES; do
   EXCLUDE''OPTIONS="$EXCLUDE''OPTIONS --exclude $i"
done
OPTIONS="$EXCLUDE''OPTIONS $OTHER''OPTIONS"

# Go through each remote host.
for BACKUP''HOST in $BACKUP''HOSTS; do
   SRC="${SSH''USER}@${BACKUP''HOST}::${BACKUP_PATH}"
   DST="$BACKUP''DIR/${BACKUP''HOST}${BACKUP_PATH}"

   # Make sure there is a valid place to put the data
   if [[ -e "$DST" ]]; then
      if [[ ==== -d "$DST" ]]; then
===
         echo "Strange: '$DST' exists, but is not a directory"
         exit 1
      fi
   else
      mkdir -p $DST
      echo "created $DST"
   fi

   # Backup
   echo "Doing this: $BINARY $OPTIONS $SRC $DST"
   echo "Backing up $BACKUP_HOST"
   $BINARY $OPTIONS $SRC $DST

   # How did it go?
   if [[ $? -eq 0 ]]; then
      # It went well; removing stuff older than MAXAGE
      $BINARY --force --remove-older-than $MAXAGE $DST
      if [[ $? -eq 0 ]]; then
         echo "Clean-up OK"
      else
         echo "running this failed (during clean-up):"
         echo "$BINARY --force remove-older-than $MAXAGE $DST"
      fi
   else
      # It failed; don't clean up. Assume that the
      # cron system mails output to a relevant
      # recipient.
      echo "running this failed:"
      echo "$BINARY $OPTIONS $SRC $DST"
   fi
done
#

Back to ContribScripts

Back to RdiffBackupWiki