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