155 lines
3.3 KiB
Text
155 lines
3.3 KiB
Text
|
#!/bin/bash
|
||
|
#
|
||
|
# script to do drive mirroring of another machine
|
||
|
# Copyright 2002, David Lane for Egressive Limited, www.egressive.com
|
||
|
#
|
||
|
#
|
||
|
VERSION=0.1
|
||
|
#
|
||
|
# Defaults
|
||
|
#
|
||
|
# default configuration file
|
||
|
DEF_CONF=/etc/egrsync/egrsync.conf
|
||
|
#
|
||
|
# default log file
|
||
|
DEF_LOG=/etc/egrsync/egrsync.log
|
||
|
#
|
||
|
# Commands
|
||
|
# the current date
|
||
|
DATE=`date '+%Y-%m-%d-%a'`
|
||
|
#
|
||
|
# a timestamp for logging purposes
|
||
|
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
|
||
|
#
|
||
|
# function to direct a message...
|
||
|
message() {
|
||
|
echo "$0: $TIMESTAMP $@" >> $LOG
|
||
|
verbose "$TIMESTAMP $@"
|
||
|
}
|
||
|
#
|
||
|
# insert a blank line into the log and on the console
|
||
|
insert_blank() {
|
||
|
echo "" >> $LOG
|
||
|
verbose ""
|
||
|
}
|
||
|
#
|
||
|
# function to direct a message...
|
||
|
verbose() {
|
||
|
if test $VERBOSE=1 ; then
|
||
|
echo "$@"
|
||
|
fi
|
||
|
}
|
||
|
#
|
||
|
# function to perform the rsyncing
|
||
|
rsync() {
|
||
|
excludes
|
||
|
message "performing rsync..."
|
||
|
for DIR in $DIRS ;
|
||
|
do
|
||
|
message "starting $DIR..."
|
||
|
rsync $FLAGS $EXCLUDES $USER@$SERVER:$DIR $BASEDIR
|
||
|
message "done with $DIR."
|
||
|
done
|
||
|
}
|
||
|
#
|
||
|
# build excludes list
|
||
|
excludes() {
|
||
|
for PAT in $EXCLUDE ;
|
||
|
do
|
||
|
EXCLUDES="$EXCLUDES --exclude $PAT"
|
||
|
done
|
||
|
}
|
||
|
#
|
||
|
#
|
||
|
# control loop, using external arguments
|
||
|
#
|
||
|
# process command line arguments
|
||
|
#
|
||
|
# set some default values, so that we can test if they've
|
||
|
# been set in the configuration file...
|
||
|
VERBOSE=0
|
||
|
CONF=0
|
||
|
LOG=""
|
||
|
#
|
||
|
# set the default mode in case somebody figures out how to get
|
||
|
# past the options below...
|
||
|
MODE=help
|
||
|
#
|
||
|
# cycle through the commandline options
|
||
|
while test $# -ne 0 ; do # while there are arguments
|
||
|
case $1 in
|
||
|
--config|-c)
|
||
|
shift # shift from the flag to the value
|
||
|
verbose "setting configuration file to $1"
|
||
|
CONF=$1 # record the value
|
||
|
;;
|
||
|
--log|-l)
|
||
|
shift # shift from the flag to the value
|
||
|
verbose "setting log file to $1"
|
||
|
LOG=$1 # record the value
|
||
|
;;
|
||
|
--verbose|-v)
|
||
|
VERBOSE=1
|
||
|
verbose "setting verbosity to true"
|
||
|
;;
|
||
|
#
|
||
|
# these are the primary (and mutually exclusive) modes
|
||
|
# of operation for this system...
|
||
|
--rsync|-r)
|
||
|
MODE=rsync
|
||
|
verbose "setting mode to $MODE"
|
||
|
;;
|
||
|
--help|-?|?|-h)
|
||
|
MODE=help
|
||
|
verbose "setting mode to $MODE"
|
||
|
;;
|
||
|
esac
|
||
|
shift
|
||
|
done
|
||
|
#
|
||
|
# set the log file appropriately
|
||
|
#
|
||
|
if test -z $LOG ; then
|
||
|
LOG=$DEF_LOG
|
||
|
fi
|
||
|
#
|
||
|
# read in config info, from the config
|
||
|
# file provided, or, if none is provided
|
||
|
# from the default file...
|
||
|
if test -f $CONF ; then
|
||
|
. $CONF
|
||
|
message "reading config file: $CONF"
|
||
|
elif test -f "$DEF_CONF" ; then
|
||
|
message "reading default config file: $DEF_CONF"
|
||
|
. "$DEF_CONF"
|
||
|
else
|
||
|
message "config file $DEF_CONF does not exist!"
|
||
|
exit 1
|
||
|
fi
|
||
|
#
|
||
|
# Now actually try to do the job we've been asked to do...
|
||
|
#
|
||
|
case $MODE in
|
||
|
rsync)
|
||
|
rsync
|
||
|
insert_blank
|
||
|
;;
|
||
|
help)
|
||
|
echo ""
|
||
|
echo "$0 version $VERSION, copyright 2002 Egressive Limited, www.egressive.com"
|
||
|
echo ""
|
||
|
echo "Use rsync to mirror a series of paths (excluding some files if desired)"
|
||
|
echo ""
|
||
|
echo "Usage: $0 {-r|-c|-l}"
|
||
|
echo "-r or --rsync - rsyncs the directories described in $DEF_CONF -
|
||
|
echo " or the conf file specifed by -c"
|
||
|
echo "-v or --verbose - give extra feedback on progress to stdout"
|
||
|
echo "-c or --config config_filename - use an alternate configuration file"
|
||
|
echo "-l or --log log_filename - use an alternate log file"
|
||
|
echo "-? or --help - display this help information"
|
||
|
echo ""
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
exit 0
|