Maintain an index of backup artifacts.
[rsync-backup] / rsync-backup.in
index 7519b12..ac9cfdc 100644 (file)
@@ -149,6 +149,33 @@ hostpath () {
 }
 
 ###--------------------------------------------------------------------------
+### Database operations.
+
+INDEXDB=@pkglocalstatedir@/index.db
+
+insert_index () {
+  host=$1 fs=$2 date=$3 vol=$4
+
+  if [ -f "$INDEXDB" ]; then
+    sqlite3 "$INDEXDB" <<EOF
+INSERT INTO idx (host, fs, date, vol)
+       VALUES ('$host', '$fs', '$date', '$vol');
+EOF
+  fi
+}
+
+delete_index () {
+  host=$1 fs=$2 date=$3
+
+  if [ -f "$INDEXDB" ]; then
+    sqlite3 "$INDEXDB" <<EOF
+DELETE FROM idx WHERE
+       host = '$host' AND fs = '$fs' AND $date = '$date';
+EOF
+  fi
+}
+
+###--------------------------------------------------------------------------
 ### Snapshot handling.
 
 ## Snapshot protocol.  Each snapshot type has a pair of functions snap_TYPE
@@ -481,8 +508,10 @@ EOF
 ### Actually taking backups of filesystems.
 
 STOREDIR=@mntbkpdir@/store
+METADIR=@mntbkpdir@/meta
 MAXLOG=14
 HASH=sha256
+unset VOLUME
 
 bkprc=0
 
@@ -528,6 +557,7 @@ expire_backups () {
        echo "delete $date"
        $verbose -n "   expire $date..."
        rm -rf $date $date.*
+       delete_index $host $fs $date
        $verbose " done"
        ;;
     esac
@@ -657,6 +687,7 @@ do_backup () {
       backup_precommit_hook $host $fs $date
       mv new $date
       mv new.fshash $date.fshash
+      insert_index $host $fs $date $VOLUME
       backup_commit_hook $host $fs $date
       mkdir hack
       ln -s $date hack/last
@@ -697,6 +728,12 @@ backup () {
     exit 15
   fi
 
+  ## Read the volume name if we don't have one already.  Again, this allows
+  ## the configuration file to provide a volume name.
+  case "${VOLUME+t}${VOLUME-nil}" in
+    nil) VOLUME=$(cat $METADIR/volume) ;;
+  esac
+
   ## Back up each requested file system in turn.
   for fs in "$@"; do