diff --git a/doc/060_forget.rst b/doc/060_forget.rst index fe0236f12..b211148cb 100644 --- a/doc/060_forget.rst +++ b/doc/060_forget.rst @@ -214,7 +214,8 @@ The ``forget`` command accepts the following policy options: run) and these snapshots will hence not be removed. .. note:: If there are not enough snapshots to keep one for each duration related - ``--keep-{within-,}*`` option, the oldest snapshot is kept additionally. + ``--keep-{within-,}*`` option, the oldest snapshot is kept additionally and + marked as ``oldest`` in the output (e.g. ``oldest hourly snapshot``). .. note:: Specifying ``--keep-tag ''`` will match untagged snapshots only. diff --git a/internal/restic/snapshot_policy.go b/internal/restic/snapshot_policy.go index 950c26c91..28f871f4a 100644 --- a/internal/restic/snapshot_policy.go +++ b/internal/restic/snapshot_policy.go @@ -256,6 +256,9 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason if val != b.Last || nr == len(list)-1 { debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val) keepSnap = true + if val == b.Last && nr == len(list)-1 { + b.reason = fmt.Sprintf("oldest %v", b.reason) + } buckets[i].Last = val if buckets[i].Count > 0 { buckets[i].Count-- @@ -275,6 +278,9 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason if val != b.Last || nr == len(list)-1 { debug.Log("keep %v, time %v, ID %v, bucker %v, val %v %v\n", b.reason, cur.Time, cur.id.Str(), i, val, b.Last) keepSnap = true + if val == b.Last && nr == len(list)-1 { + b.reason = fmt.Sprintf("oldest %v", b.reason) + } bucketsWithin[i].Last = val keepSnapReasons = append(keepSnapReasons, fmt.Sprintf("%v %v", b.reason, b.Within)) } diff --git a/internal/restic/testdata/policy_keep_snapshots_16 b/internal/restic/testdata/policy_keep_snapshots_16 index da6f43a1c..07444102b 100644 --- a/internal/restic/testdata/policy_keep_snapshots_16 +++ b/internal/restic/testdata/policy_keep_snapshots_16 @@ -68,7 +68,7 @@ "paths": null }, "matches": [ - "yearly snapshot" + "oldest yearly snapshot" ], "counters": { "yearly": 6 diff --git a/internal/restic/testdata/policy_keep_snapshots_17 b/internal/restic/testdata/policy_keep_snapshots_17 index ee728d4e0..de489d445 100644 --- a/internal/restic/testdata/policy_keep_snapshots_17 +++ b/internal/restic/testdata/policy_keep_snapshots_17 @@ -214,7 +214,7 @@ "paths": null }, "matches": [ - "yearly snapshot" + "oldest yearly snapshot" ], "counters": { "yearly": 6 diff --git a/internal/restic/testdata/policy_keep_snapshots_35 b/internal/restic/testdata/policy_keep_snapshots_35 index ece4ddbd2..afc2017dd 100644 --- a/internal/restic/testdata/policy_keep_snapshots_35 +++ b/internal/restic/testdata/policy_keep_snapshots_35 @@ -165,7 +165,7 @@ "paths": null }, "matches": [ - "yearly within 9999y" + "oldest yearly within 9999y" ], "counters": {} } diff --git a/internal/restic/testdata/policy_keep_snapshots_39 b/internal/restic/testdata/policy_keep_snapshots_39 index f5fb4b1bf..fc06d8994 100644 --- a/internal/restic/testdata/policy_keep_snapshots_39 +++ b/internal/restic/testdata/policy_keep_snapshots_39 @@ -238,8 +238,8 @@ "paths": null }, "matches": [ - "monthly snapshot", - "yearly snapshot" + "oldest monthly snapshot", + "oldest yearly snapshot" ], "counters": { "monthly": -1,