Release 1.1.1.
[rsync-backup] / rsync-backup.in
index 2c1e3b6..a48d58a 100644 (file)
@@ -308,9 +308,21 @@ unsnap_lvm () {
   vg=$1 lv=$2
 
   ## Remove the snapshot.  Sometimes LVM doesn't notice that the snapshot is
-  ## no longer in open immdiately, so try several times.
+  ## no longer in open immdiately, so try several times.  Sometimes, more
+  ## mysteriously, something is keeping the filesystem from being unmounted,
+  ## so try that several times and report on things keeping the filesystem
+  ## open.
   hostrun "unsnap-lvm $vg/$lv" "
-       umount $SNAPDIR/$lv
+       for i in 1 2 3 4; do
+         echo \";;; BEGIN fuser -mv $SNAPDIR/$lv\"
+         fuser -mv $SNAPDIR/$lv | sed 's/^/;;; /'
+         echo \";;; END fuser -mv $SNAPDIR/$lv\"
+         echo \";;; BEGIN lsof $SNAPDIR/$lv\"
+         lsof $SNAPDIR/$lv | sed 's/^/;;; /'
+         echo \";;; END lsof $SNAPDIR/$lv\"
+         if umount $SNAPDIR/$lv; then break; fi
+         sleep 2
+       done
        rc=1
        for i in 1 2 3 4; do
          if lvremove -f $vg/$lv.bkp; then rc=0; break; fi
@@ -534,6 +546,21 @@ unset VOLUME
 
 bkprc=0
 
+hash_file () {
+  file=$1
+
+  case $HASH in
+    md5 | sha1 | sha224 | sha256 | sha384 | sha512)
+      set -- $(${HASH}sum <"$file")
+      echo "$1"
+      ;;
+    *)
+      set -- $(openssl dgst -$HASH <"$file")
+      echo "$2"
+      ;;
+  esac
+}
+
 remote_fshash () {
   _hostrun $userat$host "
        umask 077
@@ -628,6 +655,9 @@ do_backup () {
   ## Maybe we need to retry the backup.
   while :; do
 
+    ## Rig checksum variables to mismatch unless they're set later.
+    hrfs=REMOTE hlfs=LOCAL
+
     ## Create and mount the remote snapshot.
     case $dryrun in
       t)
@@ -685,7 +715,16 @@ do_backup () {
     run "@$host: fshash $fs" remote_fshash
     rc_fshash=$?
     set -e
-    case $dryrun in nil) $verbose " done" ;; esac
+    case $dryrun in
+      nil)
+       hrfs=$(hash_file "new.fshash")
+       log "remote fshash $HASH checksum: $hrfs"
+       $verbose " done"
+       ;;
+      t)
+       hrfs=UNSET
+       ;;
+    esac
 
     ## Remove the snapshot.
     maybe unsnap_$snap $snapargs $fs $fsarg
@@ -706,7 +745,16 @@ do_backup () {
       nil) $verbose -n "       local fshash..." ;;
     esac
     run "local fshash $host:$fs" local_fshash || return $?
-    case $dryrun in nil) $verbose " done" ;; esac
+    case $dryrun in
+      nil)
+       hlfs=$(hash_file "$localmap")
+       log "local fshash $HASH checksum: $hlfs"
+       $verbose " done"
+       ;;
+      t)
+       hlfs=UNSET
+       ;;
+    esac
 
     ## Compare the two maps.
     set +e
@@ -730,6 +778,16 @@ do_backup () {
     esac
   done
 
+  ## Double-check the checksums.
+  if [ $hrfs != $hlfs ]; then
+    cat >&2 <<EOF
+$0: INTERNAL ERROR: fshash $HASH checksum mismatch -- aborting
+       remote fshash checksum = $hrfs
+       local fshash checksum = $hlfs
+EOF
+    exit 127
+  fi
+
   ## Glorious success.
   maybe rm -f $localmap
   case $fshash_diff in nil) ;; *) maybe rm -f $fshash_diff ;; esac