forget: Treat -1 as forever for all "last n" opts
This commit is contained in:
parent
6aca7dac21
commit
b77b0749fa
5 changed files with 3664 additions and 3 deletions
|
@ -108,8 +108,6 @@ func verifyForgetOptions(opts *ForgetOptions) error {
|
|||
}
|
||||
|
||||
if !negValFound {
|
||||
// durations := [6]restic.Duration{opts.Within, opts.WithinHourly, opts.WithinDaily,
|
||||
// opts.WithinMonthly, opts.WithinWeekly, opts.WithinYearly}
|
||||
for _, d := range [6]restic.Duration{opts.Within, opts.WithinHourly, opts.WithinDaily,
|
||||
opts.WithinMonthly, opts.WithinWeekly, opts.WithinYearly} {
|
||||
if d.Hours < -1 || d.Days < -1 || d.Months < -1 || d.Years < -1 {
|
||||
|
|
|
@ -260,13 +260,16 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots, reason
|
|||
|
||||
// Now update the other buckets and see if they have some counts left.
|
||||
for i, b := range buckets {
|
||||
if b.Count > 0 {
|
||||
if b.Count <= -1 || b.Count > 0 {
|
||||
val := b.bucker(cur.Time, nr)
|
||||
if val != b.Last {
|
||||
debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val)
|
||||
keepSnap = true
|
||||
buckets[i].Last = val
|
||||
buckets[i].Count--
|
||||
if buckets[i].Count < -1 {
|
||||
buckets[i].Count = -1
|
||||
}
|
||||
keepSnapReasons = append(keepSnapReasons, b.reason)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,6 +239,12 @@ func TestApplyPolicy(t *testing.T) {
|
|||
WithinWeekly: parseDuration("1m"),
|
||||
WithinMonthly: parseDuration("1y"),
|
||||
WithinYearly: parseDuration("9999y")},
|
||||
{Last: -1}, // keep all
|
||||
{Last: -1, Hourly: -1}, // keep all (Last overrides Hourly)
|
||||
// {Hourly: -1}, // keep all hourlies
|
||||
// {Daily: -1}, // keep all dailies
|
||||
// {Daily: -1, Weekly: 4}, // keep all dailies and 4 weeklies
|
||||
// {Daily: 3, Weekly: -1}, // keep 3 dailies and all weeklies
|
||||
}
|
||||
|
||||
for i, p := range tests {
|
||||
|
|
1782
internal/restic/testdata/policy_keep_snapshots_36
vendored
Normal file
1782
internal/restic/testdata/policy_keep_snapshots_36
vendored
Normal file
File diff suppressed because it is too large
Load diff
1872
internal/restic/testdata/policy_keep_snapshots_37
vendored
Normal file
1872
internal/restic/testdata/policy_keep_snapshots_37
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue