#!/bin/bash
#
# usage: snaprsync <setting>... <positionals>
-# <setting> is ---<name>=<value>
+# <setting> is --<name>=<value>
# <positionals> are assigned to unused mandatory values in order
# mandatory:
# rhost device mountpoint localarea
retcdir=/etc/chiark-backup
rvardir=/var/lib/chiark-backup
bwlimit=
+ subdir=.
+ rsyncopts=
+ summer=summer
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;"; }
+nb_echo () { (echo "$@"); } # See Debian #382798
+x () { nb_echo "+ $@"; "$@"; }
+xspawned () { eval "${1}pid=$!; nb_echo \"+[$!] ($1) &\";"; }
+xwait () { eval "nb_echo \"+[\$${1}pid] ($1)...\"; wait \$${1}pid;"; }
while true; do
case "$1" in
- --?*=?*)
+ --?*=*)
name=${1#--}; name=${name%%=*}
value=${1#--*=}
case "$name" in
rhost|device|mountpoint|localarea);;
- localprevious|rsharedir|retcdir|rvardir|bwlimit);;
+ localprevious|snapkind|rsharedir|retcdir|rvardir|bwlimit);;
+ subdir|rsyncopts|summer);;
*) badusage "unknown setting $name";;
esac
eval "$name=\$value"
test -d $localarea || x mkdir $localarea
ournode=`uname -n`
rsumsfile=for-$ournode.sums
-summer='summer -ACDbtqf'
+summer="$summer -ACDbtqf"
td=/dev/enoent
rc=12
exec 4<>$td/sentinel
x ssh $rhost "$sshpfx $rsharedir/snap-drop"
+ssh $rhost "
+ $sshpfx
+ set -e
+ cd $rvardir
+ echo '$retcdir/snap/$snapkind drop $rvardir' >snap-drop.new
+ mv snap-drop.new snap-drop
+"
x ssh $rhost "$sshpfx $retcdir/snap/$snapkind snap $rvardir $device $mountpoint"
ssh $rhost <$td/sentinel 4<&- "
$sshpfx
cd ..
" &
xspawned rsum
-x $rsync -aHSxz --numeric-ids --delete \
+x $rsync -aHSxz --numeric-ids --delete $rsyncopts \
${localprevious:+--link-dest} $localprevious \
- $rhost:$rvardir/snap-mount/. $localarea/.
+ $rhost:$rvardir/snap-mount/$subdir $localarea/.
date -u "+ $datefmt rsyncdone"
exec 3>$localarea,lsums
(cd $localarea && \
- $summer .) &
+ $summer . >&3) &
xspawned lsum
exec 3>&-
date -u "+ $datefmt sumsdone"
x ssh $rhost "$sshpfx $rsharedir/snap-drop"
-if [ "x${localprevious}" != x ]; then
+if [ "x${localprevious}" != x ] && test -f "$localprevious,rsums"; then
cp "$localprevious,rsums" "$localarea,rsums"
fi
x $rsync -p \