X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;ds=sidebyside;f=backup%2Fsnaprsync;h=67716bbce66671c7e50d022d8dfeeeb29778fc1f;hb=307c42c2cd5bfa800902805ce99c5558f1afcfd0;hp=a2bc96de8f058a9a8bdc1c0e4d4dd915491f0ff7;hpb=26f2a22823fa7991c485e304e642c8f1ef712ddc;p=chiark-utils.git diff --git a/backup/snaprsync b/backup/snaprsync index a2bc96d..67716bb 100755 --- a/backup/snaprsync +++ b/backup/snaprsync @@ -11,9 +11,14 @@ rsharedir=/usr/share/chiark-backup retcdir=/etc/chiark-backup rvardir=/var/lib/chiark-backup + bwlimit= + +set -e badusage () { echo >&2 "snaprsync: bad usage: $1"; exit 12; } x () { echo "+ $@"; "$@"; } +xspawned () { eval "${1}pid=$!; echo \"+[$!] ($1) &\";"; } +xwait () { eval "echo \"+[\$${1}pid] ($1)...\"; wait \$${1}pid;"; } while true; do case "$1" in @@ -22,7 +27,7 @@ while true; do value=${1#--*=} case "$name" in rhost|device|mountpoint|localarea);; - localprevious|rsharedir|retcdir|rvardir);; + localprevious|rsharedir|retcdir|rvardir|bwlimit);; *) badusage "unknown setting $name";; esac eval "$name=\$value" @@ -43,8 +48,10 @@ for name in rhost device mountpoint localarea; do done datefmt='%Y-%m-%d %H:%M:%S Z' +rsync="rsync ${bwlimit:+--bwlimit} $bwlimit" +export RSYNC_RSH='ssh -o compression=no' -ssh $rhost "date -u '+$rhost $datefmt'" +ssh $rhost "date -u '+$rhost $datefmt start'" ssh $rhost id ssh $rhost ls -d $rsharedir ssh $rhost ls -d $rvardir @@ -52,27 +59,65 @@ ssh $rhost ls -d $rvardir test -d $localarea || x mkdir $localarea ournode=`uname -n` rsumsfile=for-$ournode.sums +summer='summer -ACDbtqf' + +td=/dev/enoent +rc=12 +trap 'rm -rf $td; exit $rc' 0 +td=`mktemp -td` + +mkfifo -m 600 $td/sentinel +exec 4<>$td/sentinel x ssh $rhost "$rsharedir/snap-drop" x ssh $rhost "$retcdir/snap/$snapkind snap $rvardir $device $mountpoint" -ssh $rhost " - set -ex +ssh $rhost <$td/sentinel 4<&- " + set -e + date -u '+$rhost $datefmt main' + exec 3<&0 0$rsumsfile cd snap-mount - summer -Cqf . >&3 - date -u +'sums done $datefmt' + $summer . | sort -t' ' -k2 >&3 + test x\"\${PIPESTATUS[*]}\" = 'x0 0' + date -u '+$rhost $datefmt sumsdone' cd .. " & -fixme kill this thing if we die -rsumpid=$! -RSYNC_RSH='ssh -o compression=no' \ - x rsync -aHSxz --numeric-ids --delete \ +xspawned rsum +x $rsync -aHSxz --numeric-ids --delete \ ${localprevious:+--link-dest} $localprevious \ $rhost:$rvardir/snap-mount/. $localarea/. -wait $rsumpid +date -u "+ $datefmt rsyncdone" + +exec 3>$localarea,lsums +(cd $localarea && \ + $summer . | sort -t' ' -k2 >&3 && \ + test x"${PIPESTATUS[*]}" = 'x0 0') & +xspawned lsum +exec 3>&- + +xwait rsum +exec 4<&- +date -u "+ $datefmt sumsdone" x ssh $rhost "$rsharedir/snap-drop" -RSYNC_RSH=ssh rsync -p - fixme use localprevious,rsums as seed if available - $rhost:$rvardir/$rsumsfile $localarea,rsums + +if [ "x${localprevious}" != x ]; then + cp "$localprevious,rsums" "$localarea,rsums" +fi +x $rsync -p \ + $rhost:$rvardir/$rsumsfile \ + "$localarea,rsums" + +xwait $lsum +date -u "+ $datefmt checking" + +set +e +x diff -u "$localarea,rsums" "$localarea,lsums" >"$localarea,sumsdiff" +diffrc=$? +set -e +test $diffrc = 0 || test $diffrc = 1 + +date -u "+ $datefmt checked $diffrc" +rc=$diffrc