#!/bin/bash # sofar - 20040201 - generic rsync script usable by mirror sites # striker - 20040520 - tweaks (ignore, debug) and fixes (rsync detection) # striker - 20060422 - remove perl regexp requirement on grep -- disables IGNORE # USAGE: ./rsync-lunar.sh [--debug] [RSYNC OPTIONS] # # (--debug must be first if extra options are specified) # rules: # 1) please rsync only once an hour MAXIMUM # 2) please rsync AFTER HH:20:SS, before that the server may be occupied # with rolling out tarballs. # 3) please inform us that you wll be rsyncing # 4) please monitor this rsync process, people may want to "depend" on this # mirror to be updated. Although we do not advice this, still, it's not # nice # # the first time you sync you MAY increase the bandwidth usage to 250 # maximum to prevent it from taking forever. Acceptable for normal # rsyncing is MAXIMUM 50 # BWLIMIT=250 # the lockfile needs to be in a writeable directory by the user that runs # this script in his crontab... best make this a separate user, and not # nobody... LOCK_FILE="/var/lock/rsync-lunar.lock" # the mirror location also needs to be writeable MIRROR_DIR="/home/Mirrors/mirror000/htdocs/" # this is the rsync URL that points to the lunar rsync repository: MASTER="lunar-linux.org::lunar/" # End configuration, begin script... ######################################################################### ######################################################################### if [ -z "$(pgrep '^rsync$')" ] ; then if [ -e $LOCK_FILE ] ; then # Stale lockfile rm -f $LOCK_FILE fi else if [ -e $LOCK_FILE ] ; then PID=`cat $LOCK_FILE` if [ ! -z "$PID" ] ; then if [ ! -d /proc/$PID ] ; then # Stale lockfile rm -f $LOCK_FILE else # rsync is running. echo "Warning: rsync already running." exit fi fi fi fi if [[ "$1" == "--debug" ]]; then DEBUG=1 if [ -z "$2" ]; then EXTRA="" else EXTRA=`echo $@ | cut -d\ -f 2-` fi ARGS="-vvaz --stats ${BWLIMIT:+--bwlimit $BWLIMIT} --progress --stats --delete $EXTRA" else ARGS="-qaz ${BWLIMIT:+--bwlimit $BWLIMIT} --delete $@" fi if [ ! -e $LOCK_FILE ] ; then if [[ "$DEBUG" == "1" ]]; then echo $$ > $LOCK_FILE && rsync $ARGS $MASTER $MIRROR_DIR else echo $$ > $LOCK_FILE && rsync $ARGS $MASTER $MIRROR_DIR 2>&1| \ grep -v "^delete_one: *unlink *" | \ grep -v "some files could not be transferred" fi rm -f $LOCK_FILE fi ######################################################################### ######################################################################### # WHEE!! EOF!