145 lines
3.3 KiB
Bash
Executable file
145 lines
3.3 KiB
Bash
Executable file
#!/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/egrsynclogs/egrsynclogs.conf
|
|
#
|
|
# default log file
|
|
DEF_LOG=/var/log/egrsynclogs.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
|
|
do_rsync() {
|
|
message "performing rsync of $SERVER..."
|
|
for DIR in $DIRS ;
|
|
do
|
|
message "starting $DIR on $SERVER (as $USER) into $BASEDIR..."
|
|
rsync $FLAGS $EXCLUDES $USER@$SERVER:$DIR $BASEDIR >> $LOG
|
|
message "done with $DIR."
|
|
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=do_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
|
|
do_rsync)
|
|
do_rsync
|
|
insert_blank
|
|
;;
|
|
help)
|
|
echo ""
|
|
echo "$0 version $VERSION, copyright 2005 Egressive Limited, www.egressive.com"
|
|
echo ""
|
|
echo "Use rsync to mirror a series files with certain permissions on one machine on this machine."
|
|
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
|