some changes in anonftpsync
Hello,
I looked with anonftpsync and came up with a few changes:
The umask in anonftpsync is being set on two places - in "if" block when
creating {TO}/project/trace and after changing to $HOME (is this really
needed)
Many used experessions are still unquoted, I have quoted them but I left
some I expect not to be potential source of problems
The LOGFILE could be based on RSYNC_DIR so the same file can be used for
mirrorring of more directories (e.g. debian and debian-volatile)
I think that savelog should be called BEFORE sync is done, to have
one more logfile available and log from last run in $LOGFILE, not
$LOGFILE.0
- what should grep '[r]'sync do except searching for "rsync" ?
Comments anyone?
--- anonftpsync.orig 2008-02-26 23:24:46.000000000 +0100
+++ anonftpsync 2008-02-29 11:44:49.000000000 +0100
@@ -31,7 +31,7 @@
# the mirrors file for the site you have chosen to mirror.
# (mandatory)
-RSYNC_DIR=debian/
+RSYNC_DIR=debian
# LOGDIR is the directory where the logs will be written to
# (mandatory)
@@ -76,11 +76,11 @@
EXCLUDE=
-# MAILTO is the address to send logfiles to;
+# MAILTO is(are) the address(es) to send logfiles to;
# if it is not defined, no mail will be sent
# (optional)
-MAILTO=
+MAILTO=""
# LOCK_TIMEOUT is a timeout in minutes. Defaults to 360 (6 hours).
# This program creates a lock to ensure that only one copy
@@ -100,7 +100,7 @@
# . ftpsync.conf
# export RSYNC_PASSWORD
-# RSYNC_HOST=$RSYNC_USER@$RSYNC_HOST
+# RSYNC_HOST="$RSYNC_USER@$RSYNC_HOST"
#-----------------------------------------------------------------------------#
@@ -111,10 +111,13 @@
exit 2
fi
+# Set the umask to be group writable
+#
+umask 002
+
if [ ! -d "${TO}/project/trace/" ]; then
# we are running mirror script for the first time
- umask 002
- mkdir -p ${TO}/project/trace
+ mkdir -p "${TO}/project/trace"
fi
# Note: on some non-Debian systems, hostname doesn't accept -f option.
@@ -156,24 +159,20 @@
done
# Logfile
-LOGFILE=$LOGDIR/debian-mirror.log
-
-# Get in the right directory and set the umask to be group writable
-#
-cd $HOME
-umask 002
+LOGFILE="echo `\"$RSYNC_DIR\"-mirror.log | tr / _`"
+LOGFILE="$LOGDIR/$LOGFILE"
# Check to see if another sync is in progress
if [ -f "$LOCK" ]; then
# Note: this requires the findutils find; for other finds, adjust as necessary
- if [ "`find $LOCK -maxdepth 1 -amin -$LOCK_TIMEOUT`" = "" ]; then
+ if [ "`find \"$LOCK\" -maxdepth 1 -amin -$LOCK_TIMEOUT`" = "" ]; then
# Note: this requires the procps ps; for other ps', adjust as necessary
- if ps ax | grep '[r]'sync | grep -q $RSYNC_HOST; then
+ if ps ax | grep rsync | grep -q "$RSYNC_HOST"; then
echo "stale lock found, but a rsync is still running, aiee!"
exit 1
else
echo "stale lock found (not accessed in the last $LOCK_TIMEOUT minutes), forcing update!"
- rm -f $LOCK
+ rm -f "$LOCK"
fi
else
echo "current lock file exists, unable to start rsync!"
@@ -181,19 +180,21 @@
fi
fi
-touch $LOCK
+touch "$LOCK"
# Note: on some non-Debian systems, trap doesn't accept "exit" as signal
# specification. If that's the case on your system, try using "0".
-trap "rm -f $LOCK" exit
+trap "rm -f \"$LOCK\"" exit
set +e
+savelog "$LOGFILE" >/dev/null
+
# First sync /pool
rsync --recursive --links --hard-links --times \
--verbose \
--timeout=3600 \
$TMP_EXCLUDE $EXCLUDE $SOURCE_EXCLUDE \
- $RSYNC_HOST::$RSYNC_DIR/pool/ $TO/pool/ >> $LOGFILE 2>&1
+ "$RSYNC_HOST::$RSYNC_DIR/pool/" "$TO/pool/" >> "$LOGFILE" 2>&1
result=$?
if [ "$result" = 0 ]; then
@@ -205,19 +206,17 @@
--exclude "Archive-Update-in-Progress-${HOSTNAME}" \
--exclude "project/trace/${HOSTNAME}" \
$TMP_EXCLUDE $EXCLUDE $SOURCE_EXCLUDE \
- $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1
+ "$RSYNC_HOST::$RSYNC_DIR/" "$TO" >> "$LOGFILE" 2>&1
LANG=C date -u > "${TO}/project/trace/${HOSTNAME}"
else
- echo "ERROR: Help, something weird happened" | tee -a $LOGFILE
- echo "mirroring /pool exited with exitcode" $result | tee -a $LOGFILE
+ echo "ERROR: Help, something weird happened" | tee -a "$LOGFILE"
+ echo "mirroring /pool exited with exitcode $result" | tee -a "$LOGFILE"
fi
if [ -n "$MAILTO" ]; then
- mail -s "debian archive synced" $MAILTO < $LOGFILE
+ mail -s "debian archive synced" $MAILTO < "$LOGFILE"
fi
-savelog $LOGFILE >/dev/null
-
-rm $LOCK
+rm "$LOCK"
--
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Linux - It's now safe to turn on your computer.
Linux - Teraz mozete pocitac bez obav zapnut.
Reply to: