karlherrick.com

Client to Server Backups

Saturday, 15 March 2008

I have intentions to look into Bacula as a disk-to-disk backup solution, however until then I am using the following script for Kubuntu Dapper -> Debian Etch backups, and a modified one for Windows XP Home -> Debian Etch.

It all uses rsync, and requires password-less key based ssh connections. I am using rsync, OpenSSH, and for Windows XP a little Cygwin magic (including modifying this script to make it Windows friendly).

client-to-server-rsync-backup.sh

#!/usr/bin/env bash
#ver 1.0.3

BACKUPSERVERUSER=limitedUserOnServer
BACKUPSERVER=serverHostName
BACKUPCLIENT=`echo $(hostname -s) | tr '[:upper:]' '[:lower:]'`
BACKUPS=(
  #localFolder,backupDestinationParentFolder
  #/home,/media/md2/backups/clientname
  #/var/www,/media/md2/backups/clientname/var
)

if [ "$1" != "--incremental" ] && [ "$1" != "--sync" ] && [ "$1" != "--help" ]; then
  echo $0: missing operand
  echo Try '$0 --help' for more information.
elif [ "$1" = "--help" ]; then
  echo " Usage: $0 [OPTION]... [PASSTHROUGH OPTIONS]";
  echo "";
  echo "   Mandatory arguments:";
  echo "     [OPTION]";
  echo "       --incremental   add to the existing backups";
  echo "       --sync    sync the live data with the existing backup";
  echo "";
  echo "   Optional arguments:";
  echo "     [PASSTHROUGH OPTIONS]";
  echo "       Passthrough options are sent to rsync in this form from this script:";
  echo "";
  echo "       for incremental:";
  echo '         sudo rsync -avz [PASSTHROUGH OPTIONS] $SOURCE $BKUPSRVUSER@';
  echo "         $BKUPSRV:$DEST";
  echo "";
  echo "       and for sync:";
  echo '         sudo rsync -avz [PASSTHROUGH OPTIONS] --delete $SOURCE ';
  echo "         $BKUPSRVUSER@$BKUPSRV:$DEST";
  echo "";
  echo "       * This makes it easy to do something like this:";
  echo "       *   $0 --incremental "--partial --progress"";
  echo "       *";
  echo "       * Thus sending "--partial --progress" to rsync,";
  echo "       * making this script a little more interactive...";
  echo "       * read more via `man rsync'.";
else
  if [ "$1" = "--incremental" ]; then
    incremental_or_sync="";
  elif [ "$1" = "--sync" ]; then
    incremental_or_sync="--delete";
  fi

  for BACKUPS in ${BACKUPS[@]}; do
    SOURCE=`echo $BACKUPS | cut -d',' -f1`
    DESTINATION=`echo $BACKUPS | cut -d',' -f2`
    echo
    echo "# starting backup"
    echo "# from: $BACKUPCLIENT:$SOURCE"
    echo "# to: $BKUPSRV:$DEST"
    echo
    echo sudo rsync -avz $2 $inc_or_sync $SOURCE $BKUPSRVUSER@$BKUPSRV:$DEST
    sudo rsync -avz $2 $inc_or_sync $SOURCE $BKUPSRVUSER@$BKUPSRV:$DEST
    echo
  done
fi


Home

About

Portfolio

Web Apps Web Enabled Applications Corporate Sites Personal Sites
Preferences Dark Theme Light Theme Notifications
Social GitHub LinkedIn RSS Feed Icon