#! /bin/bash set -u export RSYNC_PASSWORD="peiPaiH2" RSYNCSOURCE="mirror.trivini.no@ftp.acc.umu.se::private/ubuntu/" BASEDIR="/storage/ubuntu/archive" LOCKFILE="/var/lock/ubuntu-archive-sync" LOGFILE="/var/log/ubuntu-archive-sync.log" RSYNCLOGFILE="/var/log/ubuntu-archive-rsync.log" rsynclog() { echo `date +%c` " $1" >> $RSYNCLOGFILE } log() { echo `date +%c` " $1" >> $LOGFILE } fatal() { log "FATAL: $1" echo "FATAL: $1" log "Program exit" exit 1 } warn() { log "WARNING: $1" echo "WARNING: $1" } if [ ! -d ${BASEDIR} ]; then fatal "${BASEDIR} does not exist" fi if /usr/bin/lockfile -! -l 43200 -r 0 "$LOCKFILE"; then fatal "Lockfile ($LOCKFILE) found, not starting archive sync" fi trap 'log "Removing lockfile"; rm -f $LOCKFILE; log "Sync exiting"' EXIT log "Sync starting" rsynclog "Sync starting from ${RSYNCSOURCE} to ${BASEDIR}" annotate-output +%c rsync \ --verbose \ --recursive \ --times \ --links \ --hard-links \ --stats \ --timeout 1800 \ --exclude "Packages*" \ --exclude "Sources*" \ --exclude "Release*" \ --exclude-from ~/ubuntu-mirror-exclude \ ${RSYNCSOURCE} ${BASEDIR} >> ${RSYNCLOGFILE} RET=$? # rsync return codes: # 0: Normal success # 23: Partial transfer due to error (usually Permission denied-stuff) # 24: Partial transfer due to vanished source files if [ \ $RET == 0 -o \ $RET == 23 -o \ $RET == 24 \ ]; then log "rsync first pass return code $RET, considered success" else echo "rsync first pass failed with error code $RET. Aborting." echo "Last 10 log lines:" tail -n10 ${RSYNCLOGFILE} fatal "rsync first pass failed with error code $RET" fi annotate-output +%c rsync \ --verbose \ --recursive \ --times \ --links \ --hard-links \ --stats \ --timeout 1800 \ --delete \ --delete-after \ --delete-excluded \ --exclude-from ~/ubuntu-mirror-exclude \ ${RSYNCSOURCE} ${BASEDIR} >> ${RSYNCLOGFILE} RET=$? if [ \ $RET == 0 -o \ $RET == 23 -o \ $RET == 24 \ ]; then log "rsync second pass return code $RET considered success" else echo "rsync second pass failed with error code $RET. Aborting." echo "Last 10 log lines:" tail -n10 ${RSYNCLOGFILE} fatal "rsync second pass failed with error code $RET" fi date -u > ${BASEDIR}/project/trace/$(hostname -f) log "Sync finished"