mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 12:55:18 +00:00
forget: Treat -1 as forever for all "last n" opts
This commit is contained in:
parent
6aca7dac21
commit
b77b0749fa
@ -108,8 +108,6 @@ func verifyForgetOptions(opts *ForgetOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !negValFound {
|
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,
|
for _, d := range [6]restic.Duration{opts.Within, opts.WithinHourly, opts.WithinDaily,
|
||||||
opts.WithinMonthly, opts.WithinWeekly, opts.WithinYearly} {
|
opts.WithinMonthly, opts.WithinWeekly, opts.WithinYearly} {
|
||||||
if d.Hours < -1 || d.Days < -1 || d.Months < -1 || d.Years < -1 {
|
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.
|
// Now update the other buckets and see if they have some counts left.
|
||||||
for i, b := range buckets {
|
for i, b := range buckets {
|
||||||
if b.Count > 0 {
|
if b.Count <= -1 || b.Count > 0 {
|
||||||
val := b.bucker(cur.Time, nr)
|
val := b.bucker(cur.Time, nr)
|
||||||
if val != b.Last {
|
if val != b.Last {
|
||||||
debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val)
|
debug.Log("keep %v %v, bucker %v, val %v\n", cur.Time, cur.id.Str(), i, val)
|
||||||
keepSnap = true
|
keepSnap = true
|
||||||
buckets[i].Last = val
|
buckets[i].Last = val
|
||||||
buckets[i].Count--
|
buckets[i].Count--
|
||||||
|
if buckets[i].Count < -1 {
|
||||||
|
buckets[i].Count = -1
|
||||||
|
}
|
||||||
keepSnapReasons = append(keepSnapReasons, b.reason)
|
keepSnapReasons = append(keepSnapReasons, b.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,6 +239,12 @@ func TestApplyPolicy(t *testing.T) {
|
|||||||
WithinWeekly: parseDuration("1m"),
|
WithinWeekly: parseDuration("1m"),
|
||||||
WithinMonthly: parseDuration("1y"),
|
WithinMonthly: parseDuration("1y"),
|
||||||
WithinYearly: parseDuration("9999y")},
|
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 {
|
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 New Issue
Block a user