chiark / gitweb /
rsync-backup.8, rsync-backup.in: Allow per-backup retention policy.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 14 Dec 2012 23:07:33 +0000 (23:07 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 14 Dec 2012 23:07:33 +0000 (23:07 +0000)
Now stuff like the media library doesn't keep old mistakes and changed
files forever, but we can still keep lots of history for most of the
filesystems.

rsync-backup.8
rsync-backup.in

index 20682ea90488481f467f7f5e2ebff75c5ad40e27..4ba59527a13d1f0bb26d88ad210c0406abe1f155 100644 (file)
@@ -156,7 +156,10 @@ will avoid inefficient and pointless messing about
 in this case.
 This command clears the
 .B like
 in this case.
 This command clears the
 .B like
-list.
+list, and resets the retention policy to its default (i.e., the to
+policy defined prior to the first
+.B host
+command).
 .TP
 .BI "like " "host\fR ..."
 Declare that subsequent filesystems are `similar' to like-named
 .TP
 .BI "like " "host\fR ..."
 Declare that subsequent filesystems are `similar' to like-named
@@ -197,6 +200,30 @@ or
 Expiry considers each existing dump against the policy lines in order:
 the last applicable line determines the dump's fate \(en so you should
 probably write the lines in decreasing order of duration.
 Expiry considers each existing dump against the policy lines in order:
 the last applicable line determines the dump's fate \(en so you should
 probably write the lines in decreasing order of duration.
+.PP
+Groups of
+.B retain
+commands between
+.B host
+and/or
+.B backup
+commands collectively define a retention policy.  Once a policy is
+defined, subsequent
+.B backup
+operations use the policy.  The first
+.B retain
+command after a
+.B host
+or
+.B backup
+command clears the policy and starts defining a new one.  The policy
+defined before the first
+.B host
+is the
+.I default
+policy: at the start of each
+.B host
+stanza, the policy is reset to the default.
 .TP
 .BI "retry " count
 The
 .TP
 .BI "retry " count
 The
index 292c6ebefe869d5ab2f12d19286706c876abb927..7519b125e2ee8455cf67afe793cbbd6adcebf81b 100644 (file)
@@ -130,7 +130,7 @@ hostrun () {
 
 _hostrun () {
   h=$1 cmd=$2
 
 _hostrun () {
   h=$1 cmd=$2
-  ## Like hostrun, but without the complicated logging, but targetted at a
+  ## Like hostrun, but without the complicated logging, and targetted at a
   ## specific host.
 
   if localp $h; then sh -c "$cmd"
   ## specific host.
 
   if localp $h; then sh -c "$cmd"
@@ -667,10 +667,14 @@ do_backup () {
   $verbose "   commit"
 
   ## Expire old backups.
   $verbose "   commit"
 
   ## Expire old backups.
+  case "${expire_policy+t},${default_policy+t}" in
+    ,t) expire_policy=$default_policy ;;
+  esac
   case "${expire_policy+t},$dryrun" in
     t,nil) run "expiry for $host:$fs" expire_backups ;;
     t,t) expire_backups ;;
   esac
   case "${expire_policy+t},$dryrun" in
     t,nil) run "expiry for $host:$fs" expire_backups ;;
     t,t) expire_backups ;;
   esac
+  clear_policy=t
 
   ## Report success.
   case $dryrun in
 
   ## Report success.
   case $dryrun in
@@ -776,13 +780,23 @@ backup () {
 ###--------------------------------------------------------------------------
 ### Configuration functions.
 
 ###--------------------------------------------------------------------------
 ### Configuration functions.
 
-host () { host=$1; like=; $verbose "host $host"; }
+host () {
+  host=$1
+  like=
+  case "${expire_policy+t},${default_policy+t}" in
+    t,) default_policy=$expire_policy ;;
+  esac
+  unset expire_policy
+  $verbose "host $host"
+}
+
 snaptype () { snap=$1; shift; snapargs="$*"; retry=0; }
 rsyncargs () { rsyncargs="$*"; }
 like () { like="$*"; }
 retry () { retry="$*"; }
 
 retain () {
 snaptype () { snap=$1; shift; snapargs="$*"; retry=0; }
 rsyncargs () { rsyncargs="$*"; }
 like () { like="$*"; }
 retry () { retry="$*"; }
 
 retain () {
+  case $clear_policy in t) unset expire_policy; clear_policy=nil ;; esac
   expire_policy="${expire_policy+$expire_policy
 }$*"
 }
   expire_policy="${expire_policy+$expire_policy
 }$*"
 }