2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

forget: Add comments to snapshot policy

This commit is contained in:
Michael Eischer 2023-06-16 21:28:49 +02:00
parent 182b9796e4
commit 1257c2c075

View File

@ -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