chiark / gitweb /
wip
authorianmdlvl <ianmdlvl>
Wed, 7 Jun 2006 00:11:28 +0000 (00:11 +0000)
committerianmdlvl <ianmdlvl>
Wed, 7 Jun 2006 00:11:28 +0000 (00:11 +0000)
backup/snaprsync

index a2bc96de8f058a9a8bdc1c0e4d4dd915491f0ff7..c9e77fd2961ceb2ecad8d3ad747d84fcdef27920 100755 (executable)
@@ -11,6 +11,9 @@
        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 "+ $@"; "$@"; }
@@ -22,7 +25,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 +46,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
@@ -53,26 +58,40 @@ test -d $localarea || x mkdir $localarea
 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"