chiark / gitweb /
wip snaprsync
authorianmdlvl <ianmdlvl>
Sat, 3 Jun 2006 00:53:02 +0000 (00:53 +0000)
committerianmdlvl <ianmdlvl>
Sat, 3 Jun 2006 00:53:02 +0000 (00:53 +0000)
backup/snaprsync [new file with mode: 0755]
cprogs/summer.c
debian/changelog

diff --git a/backup/snaprsync b/backup/snaprsync
new file mode 100755 (executable)
index 0000000..a2bc96d
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/bash
+#
+# usage: snaprsync <setting>... <positionals>
+#  <setting> is ---<name>=<value>
+#  <positionals> are assigned to unused mandatory values in order
+# mandatory:
+#   rhost device mountpoint localarea 
+# optional:
+       localprevious=
+       snapkind=lvm
+       rsharedir=/usr/share/chiark-backup 
+       retcdir=/etc/chiark-backup
+       rvardir=/var/lib/chiark-backup
+
+badusage () { echo >&2 "snaprsync: bad usage: $1"; exit 12; }
+x () { echo "+ $@"; "$@"; }
+
+while true; do
+       case "$1" in
+       --?*=?*)
+               name=${1#--}; name=${name%%=*}
+               value=${1#--*=}
+               case "$name" in
+               rhost|device|mountpoint|localarea);;
+               localprevious|rsharedir|retcdir|rvardir);;
+               *) badusage "unknown setting $name";;
+               esac
+               eval "$name=\$value"
+               ;;
+       --)     shift; break ;;
+       -*)     badusage "unknown option $1" ;;
+       *)      break ;;
+       esac
+       shift
+done
+
+for name in rhost device mountpoint localarea; do
+       eval "value=\$$name"
+       if [ "x$value" != x ]; then continue; fi
+       if [ $# = 0 ]; then badusage "no value for setting $name"; fi
+       eval "$name=$1"
+       shift
+done
+
+datefmt='%Y-%m-%d %H:%M:%S Z'
+
+ssh $rhost "date -u '+$rhost $datefmt'"
+ssh $rhost id
+ssh $rhost ls -d $rsharedir
+ssh $rhost ls -d $rvardir
+
+test -d $localarea || x mkdir $localarea
+ournode=`uname -n`
+rsumsfile=for-$ournode.sums
+
+x ssh $rhost "$rsharedir/snap-drop"
+x ssh $rhost "$retcdir/snap/$snapkind snap $rvardir $device $mountpoint"
+ssh $rhost "
+  set -ex
+  cd $rvardir
+  umask 077
+  exec 3>$rsumsfile
+  cd snap-mount
+  summer -Cqf . >&3
+  date -u +'sums done $datefmt'
+  cd ..
+" &
+fixme kill this thing if we die
+rsumpid=$!
+RSYNC_RSH='ssh -o compression=no' \
+ 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
index ca65fc684279ddfd08402a49e1f54bd9e195fe12..b442c711764b875b86356c4eaf6edb0231617a1a 100644 (file)
@@ -25,7 +25,7 @@
 #define MAXDEPTH 1024
 #define CSUMXL 32
 
-static int quiet=0;
+static int quiet=0, hidectime=0;
 static FILE *errfile;
 
 static void fn_escaped(FILE *f, const char *fn) {
@@ -160,15 +160,17 @@ static int item(const char *path, const struct stat *stab,
     else linktarg[r]= 0;
   }
 
-  printf(" %10lu %4d %4o %10ld %10ld %10lu %10lu %10lu ",
+  printf(" %10lu %4d %4o %10ld %10ld %10lu %10lu ",
         (unsigned long)stab->st_size,
         (int)stab->st_nlink,
         (unsigned)stab->st_mode & 07777U,
         (unsigned long)stab->st_uid,
         (unsigned long)stab->st_gid,
         (unsigned long)stab->st_atime,
-        (unsigned long)stab->st_mtime,
-        (unsigned long)stab->st_ctime);
+        (unsigned long)stab->st_mtime);
+  if (!hidectime)
+    printf("%10lu ",
+          (unsigned long)stab->st_ctime);
   fn_escaped(stdout, path);
 
   if (S_ISLNK(stab->st_mode)) {
@@ -226,6 +228,9 @@ int main(int argc, const char *const *argv) {
       case 'q':
        quiet= 1;
        break;
+      case 'C':
+       hidectime= 1;
+       break;
       case 'f':
        errfile= stdout;
        break;
index d59c02c7fb4f5fa8571a75764b39d4c814c9ee46..3f183f897526451eaf6a4ac4234f4cc1804afcd7 100644 (file)
@@ -1,5 +1,6 @@
 chiark-utils (4.0.99.0.21) unstable; urgency=low
 
+  * Working on new `snaprsync' script.
   * New `summer' checksumming program with no manpage.
 
  --