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).
36 # export RSYNC_PASSWORD
37 # RSYNC_HOST=$RSYNC_USER@$RSYNC_HOST
39 #-----------------------------------------------------------------------------#
41 # Check for some environment variables
42 if [ -z $TO ] || [ -z $RSYNC_HOST ] || [ -z $RSYNC_DIR ] || [ -z $LOGDIR ]; then
43 echo "One of the following variables seems to be empty:"
44 echo "TO, RSYNC_HOST, RSYNC_DIR or LOGDIR"
48 # Note: on some non-Debian systems, hostname doesn't accept -f option.
49 # If that's the case on your system, make sure hostname prints the full
50 # hostname, and remove the -f option. If there's no hostname command,
51 # explicitly replace `hostname -f` with the hostname.
53 HOSTNAME=`hostname -f`
55 # The hostname must match the "Site" field written in the list of mirrors.
56 # If hostname doesn't returns the correct value, fill and uncomment below
57 HOSTNAME=mirror.csclub.uwaterloo.ca
59 LOCK="${TO}/Archive-Update-in-Progress-${HOSTNAME}"
61 # The temp directory used by rsync --delay-updates is not
62 # world-readable remotely. It must be excluded to avoid errors.
63 TMP_EXCLUDE="--exclude .~tmp~/"
66 LOGFILE=$LOGDIR/debian-mirror.log
68 # Get in the right directory and set the umask to be group writable
73 # Check to see if another sync is in progress
74 if [ -f "$LOCK" ]; then
75 # Note: this requires the findutils find; for other finds, adjust as necessary
76 if [ "`find $LOCK -maxdepth 1 -amin -$LOCK_TIMEOUT`" = "" ]; then
77 # Note: this requires the procps ps; for other ps', adjust as necessary
78 if ps ax | grep '[r]'sync | grep -q $RSYNC_HOST; then
79 echo "stale lock found, but a rsync is still running, aiee!"
82 echo "stale lock found (not accessed in the last $LOCK_TIMEOUT minutes), forcing update!"
86 echo "current lock file exists, unable to start rsync!"
92 # Note: on some non-Debian systems, trap doesn't accept "exit" as signal
93 # specification. If that's the case on your system, try using "0".
94 trap "rm -f $LOCK" exit
98 # Now sync the remaining stuff
99 rsync --recursive --links --hard-links --times --verbose --delay-updates --delete-after \
100 --exclude "Archive-Update-in-Progress-${HOSTNAME}" \
101 --address=$ADDRESS $TMP_EXCLUDE \
102 $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1
104 savelog $LOGFILE >/dev/null