[Novalug] backup/mirror script

Angelo Bertolli angelo at freeshell.org
Mon Apr 16 20:59:10 EDT 2007


Hi, I was wondering if I could get some feedback on a backup bash script 
I wrote for rsync.  If anyone's interested I would like comments on any 
problems with it.  I also don't know what return codes I should really use.

#!/bin/bash
# backup-host - makes a mirror of a particular host, requires root on 
the host
# Copyright (C) 2007 - Angelo Bertolli
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; version 2 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

usage="$(basename $0) host [ip-address]"

# Network settings
host=$1
ip=$2
port=22
timeout=5

# Exclude file list
exfile="/mnt/backup/rsync/exclude.list"

# rsync
ropts="-avzH --progress --stats --numeric-ids --delete --delete-excluded"
dest="/mnt/backup/rsync"

if [ "$ip" != "" ]
then
   if nc -v -z -w $timeout $ip $port
   then
      mkdir -p $dest/$host
      rsync $ropts --exclude-from $exfile $ip:/ $dest/$host/
   else
      echo "Usage: $usage"
      exit -1
   fi
elif [ "$host" != "" ]
then
   if nc -v -z -w $timeout $host $port
   then
      mkdir -p $dest/$host
      rsync $ropts --exclude-from $exfile $host:/ $dest/$host/
   else
      echo "Usage: $usage"
      exit -1
   fi
else
   echo "Usage: $usage"
   exit 65
fi

exit 0

Thanks.

-- 
Angelo Bertolli
Please remove my email address from your post when replying
[Tech http://bitfreedom.com | Gaming http://heroesonly.com]



More information about the Novalug mailing list