#!/bin/sh set -u RSYNCSOURCE=rsync://ftp.acc.umu.se/ubuntu-releases LOCKFILE="/var/lock/ubuntu-releases-sync" LOGFILE="/var/log/ubuntu-releases-sync.log" RSYNCLOGFILE="/var/log/ubuntu-releases-rsync.log" BASEDIR=/storage/ubuntu/releases 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 /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 \ ${RSYNCSOURCE} ${BASEDIR} >> ${RSYNCLOGFILE} log "Sync finished"