forked from TrueCloudLab/restic
Merge pull request #1194 from mungomat/bugfix_bucker_always
fix: bucker
This commit is contained in:
commit
62df316356
8 changed files with 209 additions and 30 deletions
|
@ -34,34 +34,34 @@ func (e ExpirePolicy) Empty() bool {
|
|||
}
|
||||
|
||||
// ymdh returns an integer in the form YYYYMMDDHH.
|
||||
func ymdh(d time.Time) int {
|
||||
func ymdh(d time.Time, _ int) int {
|
||||
return d.Year()*1000000 + int(d.Month())*10000 + d.Day()*100 + d.Hour()
|
||||
}
|
||||
|
||||
// ymd returns an integer in the form YYYYMMDD.
|
||||
func ymd(d time.Time) int {
|
||||
func ymd(d time.Time, _ int) int {
|
||||
return d.Year()*10000 + int(d.Month())*100 + d.Day()
|
||||
}
|
||||
|
||||
// yw returns an integer in the form YYYYWW, where WW is the week number.
|
||||
func yw(d time.Time) int {
|
||||
func yw(d time.Time, _ int) int {
|
||||
year, week := d.ISOWeek()
|
||||
return year*100 + week
|
||||
}
|
||||
|
||||
// ym returns an integer in the form YYYYMM.
|
||||
func ym(d time.Time) int {
|
||||
func ym(d time.Time, _ int) int {
|
||||
return d.Year()*100 + int(d.Month())
|
||||
}
|
||||
|
||||
// y returns the year of d.
|
||||
func y(d time.Time) int {
|
||||
func y(d time.Time, _ int) int {
|
||||
return d.Year()
|
||||
}
|
||||
|
||||
// always returns a unique number for d.
|
||||
func always(d time.Time) int {
|
||||
return int(d.UnixNano())
|
||||
func always(d time.Time, nr int) int {
|
||||
return nr
|
||||
}
|
||||
|
||||
// ApplyPolicy returns the snapshots from list that are to be kept and removed
|
||||
|
@ -79,7 +79,7 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots) {
|
|||
|
||||
var buckets = [6]struct {
|
||||
Count int
|
||||
bucker func(d time.Time) int
|
||||
bucker func(d time.Time, nr int) int
|
||||
Last int
|
||||
}{
|
||||
{p.Last, always, -1},
|
||||
|
@ -90,7 +90,7 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots) {
|
|||
{p.Yearly, y, -1},
|
||||
}
|
||||
|
||||
for _, cur := range list {
|
||||
for nr, cur := range list {
|
||||
var keepSnap bool
|
||||
|
||||
// Tags are handled specially as they are not counted.
|
||||
|
@ -103,7 +103,7 @@ func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots) {
|
|||
// Now update the other buckets and see if they have some counts left.
|
||||
for i, b := range buckets {
|
||||
if b.Count > 0 {
|
||||
val := b.bucker(cur.Time)
|
||||
val := b.bucker(cur.Time, nr)
|
||||
if val != b.Last {
|
||||
keepSnap = true
|
||||
buckets[i].Last = val
|
||||
|
|
|
@ -114,6 +114,10 @@ var testExpireSnapshots = restic.Snapshots{
|
|||
{Time: parseTimeUTC("2015-10-11 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-20 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||
{Time: parseTimeUTC("2015-10-22 10:20:30"), Tags: []string{"foo", "bar"}, Paths: []string{"path1", "path2"}},
|
||||
{Time: parseTimeUTC("2015-11-08 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-10 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-12 10:20:30")},
|
||||
|
|
35
internal/restic/testdata/policy_keep_snapshots_0
vendored
35
internal/restic/testdata/policy_keep_snapshots_0
vendored
|
@ -149,6 +149,41 @@
|
|||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": [
|
||||
"path1",
|
||||
"path2"
|
||||
],
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-20T10:20:30Z",
|
||||
"tree": null,
|
||||
|
|
|
@ -1,4 +1,34 @@
|
|||
[
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": [
|
||||
"path1",
|
||||
"path2"
|
||||
],
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2014-11-15T10:20:30Z",
|
||||
"tree": null,
|
||||
|
|
|
@ -1,4 +1,34 @@
|
|||
[
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": [
|
||||
"path1",
|
||||
"path2"
|
||||
],
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2014-11-15T10:20:30Z",
|
||||
"tree": null,
|
||||
|
|
|
@ -1,4 +1,34 @@
|
|||
[
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": [
|
||||
"path1",
|
||||
"path2"
|
||||
],
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2014-11-15T10:20:30Z",
|
||||
"tree": null,
|
||||
|
|
55
internal/restic/testdata/policy_keep_snapshots_3
vendored
55
internal/restic/testdata/policy_keep_snapshots_3
vendored
|
@ -149,6 +149,41 @@
|
|||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": [
|
||||
"path1",
|
||||
"path2"
|
||||
],
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-20T10:20:30Z",
|
||||
"tree": null,
|
||||
|
@ -522,25 +557,5 @@
|
|||
"time": "2014-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2014-08-13T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2014-08-12T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2014-08-10T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2014-08-08T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
35
internal/restic/testdata/policy_keep_snapshots_4
vendored
35
internal/restic/testdata/policy_keep_snapshots_4
vendored
|
@ -149,6 +149,41 @@
|
|||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": [
|
||||
"path1",
|
||||
"path2"
|
||||
],
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-10-22T10:20:30Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2015-10-20T10:20:30Z",
|
||||
"tree": null,
|
||||
|
|
Loading…
Reference in a new issue