diff --git a/internal/restic/snapshot_policy.go b/internal/restic/snapshot_policy.go index f5c90d6e4..28f871f4a 100644 --- a/internal/restic/snapshot_policy.go +++ b/internal/restic/snapshot_policy.go @@ -256,13 +256,13 @@ 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-- } - if nr == len(list)-1 { - b.reason = fmt.Sprintf("oldest %v", b.reason) - } keepSnapReasons = append(keepSnapReasons, b.reason) } } @@ -278,10 +278,10 @@ 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 - bucketsWithin[i].Last = val - if nr == len(list)-1 { + 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_36 b/internal/restic/testdata/policy_keep_snapshots_36 index 6023e993e..cce4cf537 100644 --- a/internal/restic/testdata/policy_keep_snapshots_36 +++ b/internal/restic/testdata/policy_keep_snapshots_36 @@ -1978,7 +1978,7 @@ "paths": null }, "matches": [ - "oldest last snapshot" + "last snapshot" ], "counters": { "last": -1 diff --git a/internal/restic/testdata/policy_keep_snapshots_37 b/internal/restic/testdata/policy_keep_snapshots_37 index 0cf643ab6..9856a83d6 100644 --- a/internal/restic/testdata/policy_keep_snapshots_37 +++ b/internal/restic/testdata/policy_keep_snapshots_37 @@ -2169,8 +2169,8 @@ "paths": null }, "matches": [ - "oldest last snapshot", - "oldest hourly snapshot" + "last snapshot", + "hourly snapshot" ], "counters": { "last": -1, diff --git a/internal/restic/testdata/policy_keep_snapshots_38 b/internal/restic/testdata/policy_keep_snapshots_38 index ef4eb6777..f5d7136d4 100644 --- a/internal/restic/testdata/policy_keep_snapshots_38 +++ b/internal/restic/testdata/policy_keep_snapshots_38 @@ -1708,7 +1708,7 @@ "paths": null }, "matches": [ - "oldest hourly snapshot" + "hourly snapshot" ], "counters": { "hourly": -1 diff --git a/internal/restic/testdata/policy_keep_snapshots_4 b/internal/restic/testdata/policy_keep_snapshots_4 index 66e5cebe2..ff572d6a0 100644 --- a/internal/restic/testdata/policy_keep_snapshots_4 +++ b/internal/restic/testdata/policy_keep_snapshots_4 @@ -1978,7 +1978,7 @@ "paths": null }, "matches": [ - "oldest last snapshot" + "last snapshot" ], "counters": { "last": 97