3 # usage: snaprsync <setting>... <positionals>
4 # <setting> is --<name>=<value>
5 # <positionals> are assigned to unused mandatory values in order
7 # rhost device mountpoint localarea
11 rsharedir=/usr/share/chiark-backup
12 retcdir=/etc/chiark-backup
13 rvardir=/var/lib/chiark-backup
24 # This file is part of chiark backup, a system for backing up GNU/Linux and
25 # other UN*X-compatible machines, as used on chiark.greenend.org.uk.
28 # Copyright (C) 1997-1998,2000-2001,2007
29 # Ian Jackson <ian@chiark.greenend.org.uk>
30 # Copyright (C) 1999 Peter Maydell <pmaydell@chiark.greenend.org.uk>
32 # This is free software; you can redistribute it and/or modify it under the
33 # terms of the GNU General Public License as published by the Free Software
34 # Foundation; either version 3, or (at your option) any later version.
36 # This is distributed in the hope that it will be useful, but WITHOUT ANY
37 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
38 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
41 # You should have received a copy of the GNU General Public License along
42 # with this program; if not, consult the Free Software Foundation's
43 # website at www.fsf.org, or the GNU Project website at www.gnu.org.
48 badusage () { echo >&2 "snaprsync: bad usage: $1"; exit 12; }
49 nb_echo () { (echo "$@"); } # See Debian #382798
50 x () { nb_echo "+ $@"; "$@"; }
51 xspawned () { eval "${1}pid=$!; nb_echo \"+[$!] ($1) &\";"; }
52 xwait () { eval "nb_echo \"+[\$${1}pid] ($1)...\"; wait \$${1}pid;"; }
57 name=${1#--}; name=${name%%=*}
60 rhost|device|mountpoint|localarea);;
61 localprevious|snapkind|rsharedir|retcdir|rvardir|bwlimit);;
62 subdir|rsyncopts|rsynccompress|sshopts|summer);;
63 *) badusage "unknown setting $name";;
68 -*) badusage "unknown option $1" ;;
74 for name in rhost device mountpoint localarea; do
76 if [ "x$value" != x ]; then continue; fi
77 if [ $# = 0 ]; then badusage "no value for setting $name"; fi
82 datefmt='%Y-%m-%d %H:%M:%S Z'
83 rsync="rsync ${bwlimit:+--bwlimit} $bwlimit"
84 export RSYNC_RSH="ssh -o compression=no $sshopts"
85 sshpfx='PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin; export PATH; '
87 ssh $sshopts $rhost "$sshpfx date -u '+$rhost $datefmt start'"
88 ssh $sshopts $rhost "$sshpfx id"
89 ssh $sshopts $rhost "$sshpfx ls -d $rsharedir"
90 ssh $sshopts $rhost "$sshpfx ls -d $rvardir"
92 test -d $localarea || x mkdir $localarea
94 rsumsfile=for-$ournode.sums
95 summer="$summer -ACDBtqfx"
99 trap 'rm -rf $td; exit $rc' 0
102 mkfifo -m 600 $td/sentinel
105 x ssh $sshopts $rhost "$sshpfx $rsharedir/snap-drop $rvardir"
106 x ssh $sshopts $rhost "
110 echo '$retcdir/snap/$snapkind drop $rvardir' >snap-drop.new
111 mv snap-drop.new snap-drop
113 x ssh $sshopts $rhost "$sshpfx $retcdir/snap/$snapkind snap $rvardir $device $mountpoint"
114 ssh $sshopts $rhost <$td/sentinel 4<&- "
117 date -u '+$rhost $datefmt main'
118 exec 3<&0 0</dev/null
119 (set +e; read x <&3; kill 0) &
125 date -u '+$rhost $datefmt sumsdone'
129 x $rsync -aHSx$rsynccompress --numeric-ids --delete $rsyncopts \
130 ${localprevious:+--link-dest} $localprevious \
131 $rhost:$rvardir/snap-mount/$subdir $localarea/.
132 date -u "+ $datefmt rsyncdone"
134 exec 3>$localarea,lsums
142 date -u "+ $datefmt sumsdone"
143 x ssh $sshopts $rhost "$sshpfx $rsharedir/snap-drop $rvardir"
145 if [ "x${localprevious}" != x ] && test -f "$localprevious,rsums"; then
146 cp "$localprevious,rsums" "$localarea,rsums"
149 $rhost:$rvardir/$rsumsfile \
153 date -u "+ $datefmt checking"
156 diff -u <(sed -e 's/^mountpoint/dir /' "$localarea,rsums") \
157 "$localarea,lsums" >"$localarea,sumsdiff"
160 test $diffrc = 0 || test $diffrc = 1
162 date -u "+ $datefmt checked $diffrc"