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 "+ $@"; "$@"; }
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"
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
ournode=`uname -n`
rsumsfile=for-$ournode.sums
+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</dev/null
+ (set +e; read x <&3; kill 0) &
cd $rvardir
umask 077
exec 3>$rsumsfile
cd snap-mount
- summer -Cqf . >&3
- date -u +'sums done $datefmt'
+ summer -Ctqf . | 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 \
+x $rsync -aHSxz --numeric-ids --delete \
${localprevious:+--link-dest} $localprevious \
$rhost:$rvardir/snap-mount/. $localarea/.
wait $rsumpid
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"