From f8d0b27dcb64f0e6f03d1c3cf2cb85277a017a98 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Fri, 14 Dec 2012 23:07:33 +0000 Subject: [PATCH] rsync-backup.8, rsync-backup.in: Allow per-backup retention policy. 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 | 29 ++++++++++++++++++++++++++++- rsync-backup.in | 18 ++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/rsync-backup.8 b/rsync-backup.8 index 20682ea..4ba5952 100644 --- a/rsync-backup.8 +++ b/rsync-backup.8 @@ -156,7 +156,10 @@ will avoid inefficient and pointless messing about 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 @@ -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. +.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 diff --git a/rsync-backup.in b/rsync-backup.in index 292c6eb..7519b12 100644 --- a/rsync-backup.in +++ b/rsync-backup.in @@ -130,7 +130,7 @@ hostrun () { _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" @@ -667,10 +667,14 @@ do_backup () { $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 + clear_policy=t ## Report success. case $dryrun in @@ -776,13 +780,23 @@ backup () { ###-------------------------------------------------------------------------- ### 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 () { + case $clear_policy in t) unset expire_policy; clear_policy=nil ;; esac expire_policy="${expire_policy+$expire_policy }$*" } -- 2.11.0