4 echo 'Usage: sync local_dir rsync_host rsync_dir [trace_host [trace_dir]]'
17 TRACE_DIR=project/trace
21 LOGDIR=/var/log/mirror/$1_$2
26 # This script originates from http://www.debian.org/mirror/anonftpsync
28 # CVS: cvs.debian.org:/cvs/webwml - webwml/english/mirror/anonftpsync
29 # Version: $Id: anonftpsync,v 1.33 2007/09/12 15:19:03 joy Exp $
31 # Note: You MUST have rsync 2.6.4 or newer, which is available in sarge
32 # and all newer Debian releases, or at http://rsync.samba.org/
35 # chmod u+x anonftpsync
37 # Set the variables below to fit your site. You can then use cron to have
38 # this script run daily to automatically update your copy of the archive.
40 # TO is the destination for the base of the Debian mirror directory
41 # (the dir that holds dists/ and ls-lR).
46 # RSYNC_HOST is the site you have chosen from the mirrors file.
47 # (http://www.debian.org/mirror/list-full)
52 # RSYNC_DIR is the directory given in the "Packages over rsync:" line of
53 # the mirrors file for the site you have chosen to mirror.
58 # LOGDIR is the directory where the logs will be written to
63 # ARCH_EXCLUDE can be used to exclude a complete architecture from
64 # mirrorring. Please use as space seperated list.
65 # Possible values are:
66 # alpha, amd64, arm, hppa, hurd-i386, i386, ia64, m68k, mipsel, mips, powerpc, s390, sh and sparc
68 # There is one special value: source
69 # This is not an architecture but will exclude all source code in /pool
72 # ARCH_EXCLUDE="alpha arm hppa hurd-i386 ia64 m68k mipsel mips s390 sparc"
74 # With a blank ARCH_EXCLUDE you will mirror all available architectures
77 # EXCLUDE is a list of parameters listing patterns that rsync will exclude, in
78 # addition to the architectures excluded by ARCH_EXCLUDE.
80 # Use ARCH_EXCLUDE to exclude specific architectures or all sources
82 # --exclude stable, testing, unstable options DON'T remove the packages of
83 # the given distribution. If you want do so, use debmirror instead.
85 # The following example would exclude mostly everything:
87 # --exclude stable/ --exclude testing/ --exclude unstable/ \
89 # --exclude *.orig.tar.gz --exclude *.diff.gz --exclude *.dsc \
90 # --exclude /contrib/ --exclude /non-free/ \
93 # With a blank EXCLUDE you will mirror the entire archive, except the
94 # architectures excluded by ARCH_EXCLUDE.
99 # LOCK_TIMEOUT is a timeout in minutes. Defaults to 360 (6 hours).
100 # This program creates a lock to ensure that only one copy
101 # of it is mirroring any one archive at any one time.
102 # Locks held for longer than the timeout are broken, unless
103 # a running rsync process appears to be connected to $RSYNC_HOST.
107 # There should be no need to edit anything below this point, unless there
110 #-----------------------------------------------------------------------------#
112 # If you are accessing a rsync server/module which is password-protected,
113 # uncomment the following lines (and edit the other file).
116 # export RSYNC_PASSWORD
117 # RSYNC_HOST=$RSYNC_USER@$RSYNC_HOST
119 #-----------------------------------------------------------------------------#
121 # Check for some environment variables
122 if [ -z $TO ] || [ -z $RSYNC_HOST ] || [ -z $RSYNC_DIR ] || [ -z $LOGDIR ]; then
123 echo "One of the following variables seems to be empty:"
124 echo "TO, RSYNC_HOST, RSYNC_DIR or LOGDIR"
128 if ! [ -d ${TO}/${TRACE_DIR} ]; then
129 # we are running mirror script for the first time
131 mkdir -p ${TO}/${TRACE_DIR}
134 # Note: on some non-Debian systems, hostname doesn't accept -f option.
135 # If that's the case on your system, make sure hostname prints the full
136 # hostname, and remove the -f option. If there's no hostname command,
137 # explicitly replace `hostname -f` with the hostname.
139 HOSTNAME=`hostname -f`
141 # The hostname must match the "Site" field written in the list of mirrors.
142 # If hostname doesn't returns the correct value, fill and uncomment below
143 HOSTNAME=mirror.csclub.uwaterloo.ca
145 LOCK="${TO}/Archive-Update-in-Progress-${HOSTNAME}"
147 # The temp directory used by rsync --delay-updates is not
148 # world-readable remotely. It must be excluded to avoid errors.
149 TMP_EXCLUDE="--exclude .~tmp~/"
151 # Exclude architectures defined in $ARCH_EXCLUDE
152 for ARCH in $ARCH_EXCLUDE; do
154 --exclude binary-$ARCH/ \
155 --exclude disks-$ARCH/ \
156 --exclude installer-$ARCH/ \
157 --exclude Contents-$ARCH.gz \
158 --exclude Contents-$ARCH.diff/ \
159 --exclude arch-$ARCH.files \
160 --exclude arch-$ARCH.list.gz \
161 --exclude *_$ARCH.deb \
162 --exclude *_$ARCH.udeb "
163 if [ "$ARCH" == "source" ]; then
167 --exclude *.diff.gz \
173 LOGFILE=$LOGDIR/debian-mirror.log
175 # Get in the right directory and set the umask to be group writable
180 # Check to see if another sync is in progress
181 if [ -f "$LOCK" ]; then
182 # Note: this requires the findutils find; for other finds, adjust as necessary
183 if [ "`find $LOCK -maxdepth 1 -amin -$LOCK_TIMEOUT`" = "" ]; then
184 # Note: this requires the procps ps; for other ps', adjust as necessary
185 if ps ax | grep '[r]'sync | grep -q $RSYNC_HOST; then
186 echo "stale lock found, but a rsync is still running, aiee!"
189 echo "stale lock found (not accessed in the last $LOCK_TIMEOUT minutes), forcing update!"
193 echo "current lock file exists, unable to start rsync!"
199 # Note: on some non-Debian systems, trap doesn't accept "exit" as signal
200 # specification. If that's the case on your system, try using "0".
201 trap "rm -f $LOCK" exit
205 # check if we need to sync
206 if [[ "$TRACE_HOST" != "" ]]; then
207 TRACE_FILE=$TO/${TRACE_DIR}/${TRACE_HOST}
208 TRACE_PRE_DATE=`ls -al $TRACE_FILE`
209 rsync --recursive --times --verbose \
211 $RSYNC_HOST::$RSYNC_DIR/${TRACE_DIR}/ \
212 $TO/${TRACE_DIR}/ >> $LOGFILE 2>&1
213 TRACE_POST_DATE=`ls -al $TRACE_FILE`
214 if [ "$TRACE_PRE_DATE" = "$TRACE_POST_DATE" ]; then
215 echo 'Trace file for' $RSYNC_HOST::$RSYNC_DIR \
216 'unchanged, not rsyncing.' >> $LOGFILE
222 rsync --recursive --links --hard-links --times --verbose \
223 $TMP_EXCLUDE $EXCLUDE $SOURCE_EXCLUDE \
225 $RSYNC_HOST::$RSYNC_DIR/pool/ $TO/pool/ >> $LOGFILE 2>&1
228 if [ 0 = $result ]; then
229 # Now sync the remaining stuff
230 rsync --recursive --links --hard-links --times --verbose --delay-updates --delete-after \
231 --exclude "Archive-Update-in-Progress-${HOSTNAME}" \
232 --exclude "${TRACE_DIR}/${HOSTNAME}" \
234 $TMP_EXCLUDE $EXCLUDE $SOURCE_EXCLUDE \
235 $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1
237 mkdir -p ${TO}/${TRACE_DIR}
238 LANG=C date -u > "${TO}/${TRACE_DIR}/${HOSTNAME}"
240 echo "ERROR: Help, something weird happened" | tee -a $LOGFILE
241 echo "mirroring /pool exited with exitcode" $result | tee -a $LOGFILE
244 savelog $LOGFILE >/dev/null