4 echo 'Usage: sync local_dir rsync_host rsync_dir'
14 LOGDIR=/var/log/mirror/$1_$2
20 # LOCK_TIMEOUT is a timeout in minutes. Defaults to 360 (6 hours).
21 # This program creates a lock to ensure that only one copy
22 # of it is mirroring any one archive at any one time.
23 # Locks held for longer than the timeout are broken, unless
24 # a running rsync process appears to be connected to $RSYNC_HOST.
28 # There should be no need to edit anything below this point, unless there
31 #-----------------------------------------------------------------------------#
33 # If you are accessing a rsync server/module which is password-protected,
34 # uncomment the following lines (and edit the other file).
38 if [[ "$RSYNC_USER" != "" ]]; then
39 RSYNC_HOST=$RSYNC_USER@$RSYNC_HOST
42 #-----------------------------------------------------------------------------#
44 # Check for some environment variables
45 if [ -z $TO ] || [ -z $RSYNC_HOST ] || [ -z $RSYNC_DIR ] || [ -z $LOGDIR ]; then
46 echo "One of the following variables seems to be empty:"
47 echo "TO, RSYNC_HOST, RSYNC_DIR or LOGDIR"
51 # Note: on some non-Debian systems, hostname doesn't accept -f option.
52 # If that's the case on your system, make sure hostname prints the full
53 # hostname, and remove the -f option. If there's no hostname command,
54 # explicitly replace `hostname -f` with the hostname.
56 HOSTNAME=`hostname -f`
58 # The hostname must match the "Site" field written in the list of mirrors.
59 # If hostname doesn't returns the correct value, fill and uncomment below
60 HOSTNAME=mirror.csclub.uwaterloo.ca
62 LOCK="${TO}/Archive-Update-in-Progress-${HOSTNAME}"
64 # The temp directory used by rsync --delay-updates is not
65 # world-readable remotely. It must be excluded to avoid errors.
66 TMP_EXCLUDE="--exclude .~tmp~/"
69 LOGFILE=$LOGDIR/mirror.log
71 # Get in the right directory and set the umask to be group writable
76 # Check to see if another sync is in progress
77 if [ -f "$LOCK" ]; then
78 # Note: this requires the findutils find; for other finds, adjust as necessary
79 if [ "`find $LOCK -maxdepth 1 -amin -$LOCK_TIMEOUT`" = "" ]; then
80 # Note: this requires the procps ps; for other ps', adjust as necessary
81 if ps ax | grep '[r]'sync | grep -q $RSYNC_HOST; then
82 echo "stale lock found, but a rsync is still running, aiee!" >&2
85 echo "stale lock found (not accessed in the last $LOCK_TIMEOUT minutes), forcing update!"
89 echo "current lock file exists, unable to start rsync!"
95 # Note: on some non-Debian systems, trap doesn't accept "exit" as signal
96 # specification. If that's the case on your system, try using "0".
97 trap "rm -f $LOCK" exit
101 # Now sync the remaining stuff
102 nice rsync -rlHtv --delete \
103 --exclude "Archive-Update-in-Progress-${HOSTNAME}" \
104 --timeout=3600 --address=$ADDRESS $TMP_EXCLUDE $EXTRA \
105 $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1
106 if [[ "$?" != "0" ]]; then
107 echo "ERROR: Help, something weird happened" | tee -a $LOGFILE
108 echo "mirroring /pool exited with exitcode" $result | tee -a $LOGFILE
111 savelog $LOGFILE >/dev/null