From 1257c2c075ea866cb589fa3ec570a6f8bd11a14d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 16 Jun 2023 21:28:49 +0200 Subject: [PATCH] forget: Add comments to snapshot policy --- internal/restic/snapshot_policy.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/restic/snapshot_policy.go b/internal/restic/snapshot_policy.go index 1d6e129a2..22939bd6c 100644 --- a/internal/restic/snapshot_policy.go +++ b/internal/restic/snapshot_policy.go @@ -183,6 +183,7 @@ type KeepReason struct { // according to the policy p. list is sorted in the process. reasons contains // the reasons to keep each snapshot, it is in the same order as keep. func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reasons []KeepReason) { + // sort newest snapshots first sort.Stable(list) if p.Empty() { @@ -256,6 +257,8 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason // -1 means "keep all" if b.Count > 0 || b.Count == -1 { val := b.bucker(cur.Time, nr) + // also keep the oldest snapshot if the bucket has some counts left. This maximizes the + // the history length kept while some counts are left. 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