forked from TrueCloudLab/restic
Do not use singleton counter.
Revert change for running the numbered tests as subtests.
This commit is contained in:
parent
103a491ac0
commit
7fffd408af
15 changed files with 71 additions and 74 deletions
|
@ -789,7 +789,7 @@ hours/days/weeks/months/years which have a snapshot, so those without a
|
||||||
snapshot are ignored.
|
snapshot are ignored.
|
||||||
|
|
||||||
All snapshots are evaluated counted against all matching keep-* counts. A
|
All snapshots are evaluated counted against all matching keep-* counts. A
|
||||||
single snapshot on 30-09-2017 (Sun) will count as a daily, weekly and monthly.
|
single snapshot on 2017-09-30 (Sun) will count as a daily, weekly and monthly.
|
||||||
|
|
||||||
Let's explain this with an example: Suppose you have only made a backup
|
Let's explain this with an example: Suppose you have only made a backup
|
||||||
on each Sunday for 12 weeks. Then ``forget --keep-daily 4`` will keep
|
on each Sunday for 12 weeks. Then ``forget --keep-daily 4`` will keep
|
||||||
|
@ -803,8 +803,8 @@ Another example: Suppose you make daily backups for 100 years. Then
|
||||||
``forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75``
|
``forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75``
|
||||||
will keep the most recent 7 daily snapshots, then 4 (remember, 7 dailies
|
will keep the most recent 7 daily snapshots, then 4 (remember, 7 dailies
|
||||||
already include a week!) last-day-of-the-weeks and 11 or 12
|
already include a week!) last-day-of-the-weeks and 11 or 12
|
||||||
last-day-of-the-months. (11 or 12 depends if the 5 weeklies cross a month).
|
last-day-of-the-months (11 or 12 depends if the 5 weeklies cross a month).
|
||||||
And ofcourse 75 last-day-of-the-year snapshots. All other snapshots are
|
And finally 75 last-day-of-the-year snapshots. All other snapshots are
|
||||||
removed.
|
removed.
|
||||||
|
|
||||||
Autocompletion
|
Autocompletion
|
||||||
|
|
|
@ -77,12 +77,9 @@ func y(d time.Time) int {
|
||||||
return d.Year()
|
return d.Year()
|
||||||
}
|
}
|
||||||
|
|
||||||
var a int
|
// always returns a unique number for d.
|
||||||
|
|
||||||
// always retuns a unique number for d.
|
|
||||||
func always(d time.Time) int {
|
func always(d time.Time) int {
|
||||||
a++
|
return int(d.UnixNano())
|
||||||
return a
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyPolicy returns the snapshots from list that are to be kept and removed
|
// ApplyPolicy returns the snapshots from list that are to be kept and removed
|
||||||
|
|
|
@ -57,7 +57,7 @@ var testExpireSnapshots = restic.Snapshots{
|
||||||
{Time: parseTimeUTC("2014-08-10 10:20:30")},
|
{Time: parseTimeUTC("2014-08-10 10:20:30")},
|
||||||
{Time: parseTimeUTC("2014-08-12 10:20:30")},
|
{Time: parseTimeUTC("2014-08-12 10:20:30")},
|
||||||
{Time: parseTimeUTC("2014-08-13 10:20:30")},
|
{Time: parseTimeUTC("2014-08-13 10:20:30")},
|
||||||
{Time: parseTimeUTC("2014-08-13 10:20:30")},
|
{Time: parseTimeUTC("2014-08-13 10:20:30.1")},
|
||||||
{Time: parseTimeUTC("2014-08-15 10:20:30")},
|
{Time: parseTimeUTC("2014-08-15 10:20:30")},
|
||||||
{Time: parseTimeUTC("2014-08-18 10:20:30")},
|
{Time: parseTimeUTC("2014-08-18 10:20:30")},
|
||||||
{Time: parseTimeUTC("2014-08-20 10:20:30")},
|
{Time: parseTimeUTC("2014-08-20 10:20:30")},
|
||||||
|
@ -77,7 +77,7 @@ var testExpireSnapshots = restic.Snapshots{
|
||||||
{Time: parseTimeUTC("2014-11-10 10:20:30"), Tags: []string{"foo"}},
|
{Time: parseTimeUTC("2014-11-10 10:20:30"), Tags: []string{"foo"}},
|
||||||
{Time: parseTimeUTC("2014-11-12 10:20:30"), Tags: []string{"foo"}},
|
{Time: parseTimeUTC("2014-11-12 10:20:30"), Tags: []string{"foo"}},
|
||||||
{Time: parseTimeUTC("2014-11-13 10:20:30"), Tags: []string{"foo"}},
|
{Time: parseTimeUTC("2014-11-13 10:20:30"), Tags: []string{"foo"}},
|
||||||
{Time: parseTimeUTC("2014-11-13 10:20:30"), Tags: []string{"bar"}},
|
{Time: parseTimeUTC("2014-11-13 10:20:30.1"), Tags: []string{"bar"}},
|
||||||
{Time: parseTimeUTC("2014-11-15 10:20:30"), Tags: []string{"foo", "bar"}},
|
{Time: parseTimeUTC("2014-11-15 10:20:30"), Tags: []string{"foo", "bar"}},
|
||||||
{Time: parseTimeUTC("2014-11-18 10:20:30")},
|
{Time: parseTimeUTC("2014-11-18 10:20:30")},
|
||||||
{Time: parseTimeUTC("2014-11-20 10:20:30")},
|
{Time: parseTimeUTC("2014-11-20 10:20:30")},
|
||||||
|
@ -97,7 +97,7 @@ var testExpireSnapshots = restic.Snapshots{
|
||||||
{Time: parseTimeUTC("2015-08-10 10:20:30")},
|
{Time: parseTimeUTC("2015-08-10 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-08-12 10:20:30")},
|
{Time: parseTimeUTC("2015-08-12 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-08-13 10:20:30")},
|
{Time: parseTimeUTC("2015-08-13 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-08-13 10:20:30")},
|
{Time: parseTimeUTC("2015-08-13 10:20:30.1")},
|
||||||
{Time: parseTimeUTC("2015-08-15 10:20:30")},
|
{Time: parseTimeUTC("2015-08-15 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-08-18 10:20:30")},
|
{Time: parseTimeUTC("2015-08-18 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-08-20 10:20:30")},
|
{Time: parseTimeUTC("2015-08-20 10:20:30")},
|
||||||
|
@ -117,7 +117,7 @@ var testExpireSnapshots = restic.Snapshots{
|
||||||
{Time: parseTimeUTC("2015-11-10 10:20:30")},
|
{Time: parseTimeUTC("2015-11-10 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-11-12 10:20:30")},
|
{Time: parseTimeUTC("2015-11-12 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-11-13 10:20:30")},
|
{Time: parseTimeUTC("2015-11-13 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-11-13 10:20:30")},
|
{Time: parseTimeUTC("2015-11-13 10:20:30.1")},
|
||||||
{Time: parseTimeUTC("2015-11-15 10:20:30")},
|
{Time: parseTimeUTC("2015-11-15 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-11-18 10:20:30")},
|
{Time: parseTimeUTC("2015-11-18 10:20:30")},
|
||||||
{Time: parseTimeUTC("2015-11-20 10:20:30")},
|
{Time: parseTimeUTC("2015-11-20 10:20:30")},
|
||||||
|
@ -169,7 +169,6 @@ var expireTests = []restic.ExpirePolicy{
|
||||||
|
|
||||||
func TestApplyPolicy(t *testing.T) {
|
func TestApplyPolicy(t *testing.T) {
|
||||||
for i, p := range expireTests {
|
for i, p := range expireTests {
|
||||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
|
||||||
keep, remove := restic.ApplyPolicy(testExpireSnapshots, p)
|
keep, remove := restic.ApplyPolicy(testExpireSnapshots, p)
|
||||||
|
|
||||||
t.Logf("test %d: returned keep %v, remove %v (of %v) expired snapshots for policy %v",
|
t.Logf("test %d: returned keep %v, remove %v (of %v) expired snapshots for policy %v",
|
||||||
|
@ -207,15 +206,16 @@ func TestApplyPolicy(t *testing.T) {
|
||||||
|
|
||||||
buf, err := ioutil.ReadFile(goldenFilename)
|
buf, err := ioutil.ReadFile(goldenFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error loading golden file %v: %v", goldenFilename, err)
|
t.Errorf("error loading golden file %v: %v", goldenFilename, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var want restic.Snapshots
|
var want restic.Snapshots
|
||||||
err = json.Unmarshal(buf, &want)
|
err = json.Unmarshal(buf, &want)
|
||||||
|
|
||||||
if !reflect.DeepEqual(keep, want) {
|
if !reflect.DeepEqual(keep, want) {
|
||||||
t.Fatalf("test %v: wrong result, want:\n %v\ngot:\n %v", i, want, keep)
|
t.Errorf("test %v: wrong result, want:\n %v\ngot:\n %v", i, want, keep)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
src/restic/testdata/policy_keep_snapshots_0
vendored
8
src/restic/testdata/policy_keep_snapshots_0
vendored
|
@ -120,7 +120,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-11-13T10:20:30Z",
|
"time": "2015-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
@ -270,7 +270,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-08-13T10:20:30Z",
|
"time": "2015-08-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
@ -324,7 +324,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2014-11-13T10:20:30Z",
|
"time": "2014-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null,
|
"paths": null,
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -519,7 +519,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2014-08-13T10:20:30Z",
|
"time": "2014-08-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
|
8
src/restic/testdata/policy_keep_snapshots_3
vendored
8
src/restic/testdata/policy_keep_snapshots_3
vendored
|
@ -120,7 +120,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-11-13T10:20:30Z",
|
"time": "2015-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
@ -270,7 +270,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-08-13T10:20:30Z",
|
"time": "2015-08-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
@ -324,7 +324,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2014-11-13T10:20:30Z",
|
"time": "2014-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null,
|
"paths": null,
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -519,7 +519,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2014-08-13T10:20:30Z",
|
"time": "2014-08-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
|
8
src/restic/testdata/policy_keep_snapshots_4
vendored
8
src/restic/testdata/policy_keep_snapshots_4
vendored
|
@ -120,7 +120,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-11-13T10:20:30Z",
|
"time": "2015-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
@ -270,7 +270,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-08-13T10:20:30Z",
|
"time": "2015-08-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
@ -324,7 +324,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2014-11-13T10:20:30Z",
|
"time": "2014-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null,
|
"paths": null,
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -519,7 +519,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2014-08-13T10:20:30Z",
|
"time": "2014-08-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
|
2
src/restic/testdata/policy_keep_snapshots_5
vendored
2
src/restic/testdata/policy_keep_snapshots_5
vendored
|
@ -95,7 +95,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-11-13T10:20:30Z",
|
"time": "2015-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
}
|
}
|
||||||
|
|
2
src/restic/testdata/policy_keep_snapshots_8
vendored
2
src/restic/testdata/policy_keep_snapshots_8
vendored
|
@ -75,7 +75,7 @@
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"time": "2015-11-13T10:20:30Z",
|
"time": "2015-11-13T10:20:30.1Z",
|
||||||
"tree": null,
|
"tree": null,
|
||||||
"paths": null
|
"paths": null
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue