#!/bin/sh # script by Michael Shigorin for snapshotting # ALT Linux Sisyphus locally; feel free to use and modify, would # be glad to hear back about changes # v0.2: fix STUPID bug which manifested when doing several # syncs per day *and* the first wasn't done off complete (stable) # mirror # v0.3: better $DEST handling in case of repeated rsync failures # during some period of time *but* with some data transferred # so they better not get lost and re-rsynced # v0.4: TIMESTAMP fix by Denis Smirnov (mithraen@altlinux) induced # by discussion with Dmitry Levin (ldv@altlinux) # v0.5: altlinux-release is searched in noarch instead of i586 # mirror/site-specific SRC="ftp.altlinux.org.ua::ALTLinux/Sisyphus/" BASEDIR="/var/ftp/pub/EMT/Sisyphus/" # retry params MAXCOUNT=5 TIMEOUT=60 # shouldn't need to be changed DATE=`date +%Y%m%d` LOGDIR="$BASEDIR/log/" LOGFILE="$LOGDIR/$DATE.log" DEST="$BASEDIR/.syncing/" RSYNCARGS="-av --partial --delete --bwlimit=120" RPMARGS="-qp --queryformat %{RELEASE}\n" TAGFILE="$DEST/files/noarch/RPMS/altlinux-release-Sisyphus-alt*.noarch.rpm" unset OK # init env mkdir -p "$BASEDIR" "$LOGDIR" cd "$BASEDIR" # create hardlinked copy or init dir LAST=`ls -d1 20?????? 2>/dev/null | tail -1` [ -d "$DEST" ] || mkdir -p "$DEST" [ -n "$LAST" ] && { [ `/bin/du -s "$LAST" |cut -f1` -gt `/bin/du -s "$DEST" |cut -f1` ] && { cp -alf "$LAST"/* "$DEST" } } # try to sync up for attempt in `seq 1 $MAXCOUNT`; do rsync $RSYNCARGS "$SRC" "$DEST" 2>&1 >> "$LOGFILE" && { OK="yes" break } sleep "$TIMEOUT" done [ -z "$OK" ] && exit 1 # get timestamp from specific package and move to it #TIMESTAMP=`rpm $RPMARGS $TAGFILE | tail -1 | sed 's/alt//'` TIMESTAMP=$(date +"%Y%m%d" -d "$(grep ^Date: $TAGFILE | sed 's!.*\([0-9][0-9] ... [0-9][0-9][0-9][0-9]\).*!\1!')") [ -d "$TIMESTAMP" ] && { rsync $RSYNCARGS "$DEST" "$TIMESTAMP"/ 2>&1 >> "$LOGFILE" } || { mv "$DEST" "$TIMESTAMP" 2>>"$LOGFILE" } touch -d "$DATE" "$TIMESTAMP" rm -f current ln -s "$TIMESTAMP" current rm -rf "$DEST" # that's all :) echo "** $TIMESTAMP sync OK" >> "$LOGFILE"