mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
Do not use singleton counter.
Revert change for running the numbered tests as subtests.
This commit is contained in:
parent
103a491ac0
commit
7fffd408af
@ -789,7 +789,7 @@ hours/days/weeks/months/years which have a snapshot, so those without a
|
||||
snapshot are ignored.
|
||||
|
||||
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
|
||||
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``
|
||||
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
|
||||
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
|
||||
last-day-of-the-months (11 or 12 depends if the 5 weeklies cross a month).
|
||||
And finally 75 last-day-of-the-year snapshots. All other snapshots are
|
||||
removed.
|
||||
|
||||
Autocompletion
|
||||
|
@ -77,12 +77,9 @@ func y(d time.Time) int {
|
||||
return d.Year()
|
||||
}
|
||||
|
||||
var a int
|
||||
|
||||
// always retuns a unique number for d.
|
||||
// always returns a unique number for d.
|
||||
func always(d time.Time) int {
|
||||
a++
|
||||
return a
|
||||
return int(d.UnixNano())
|
||||
}
|
||||
|
||||
// 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-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.1")},
|
||||
{Time: parseTimeUTC("2014-08-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2014-08-18 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-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{"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-18 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-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.1")},
|
||||
{Time: parseTimeUTC("2015-08-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-08-18 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-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.1")},
|
||||
{Time: parseTimeUTC("2015-11-15 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-18 10:20:30")},
|
||||
{Time: parseTimeUTC("2015-11-20 10:20:30")},
|
||||
@ -169,53 +169,53 @@ var expireTests = []restic.ExpirePolicy{
|
||||
|
||||
func TestApplyPolicy(t *testing.T) {
|
||||
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",
|
||||
i, len(keep), len(remove), len(testExpireSnapshots), p)
|
||||
t.Logf("test %d: returned keep %v, remove %v (of %v) expired snapshots for policy %v",
|
||||
i, len(keep), len(remove), len(testExpireSnapshots), p)
|
||||
|
||||
if len(keep)+len(remove) != len(testExpireSnapshots) {
|
||||
t.Errorf("test %d: len(keep)+len(remove) = %d != len(testExpireSnapshots) = %d",
|
||||
i, len(keep)+len(remove), len(testExpireSnapshots))
|
||||
}
|
||||
if len(keep)+len(remove) != len(testExpireSnapshots) {
|
||||
t.Errorf("test %d: len(keep)+len(remove) = %d != len(testExpireSnapshots) = %d",
|
||||
i, len(keep)+len(remove), len(testExpireSnapshots))
|
||||
}
|
||||
|
||||
if p.Sum() > 0 && len(keep) > p.Sum() {
|
||||
t.Errorf("not enough snapshots removed: policy allows %v snapshots to remain, but ended up with %v",
|
||||
p.Sum(), len(keep))
|
||||
}
|
||||
if p.Sum() > 0 && len(keep) > p.Sum() {
|
||||
t.Errorf("not enough snapshots removed: policy allows %v snapshots to remain, but ended up with %v",
|
||||
p.Sum(), len(keep))
|
||||
}
|
||||
|
||||
for _, sn := range keep {
|
||||
t.Logf("test %d: keep snapshot at %v %s\n", i, sn.Time, sn.Tags)
|
||||
}
|
||||
for _, sn := range remove {
|
||||
t.Logf("test %d: forget snapshot at %v %s\n", i, sn.Time, sn.Tags)
|
||||
}
|
||||
for _, sn := range keep {
|
||||
t.Logf("test %d: keep snapshot at %v %s\n", i, sn.Time, sn.Tags)
|
||||
}
|
||||
for _, sn := range remove {
|
||||
t.Logf("test %d: forget snapshot at %v %s\n", i, sn.Time, sn.Tags)
|
||||
}
|
||||
|
||||
goldenFilename := filepath.Join("testdata", fmt.Sprintf("policy_keep_snapshots_%d", i))
|
||||
goldenFilename := filepath.Join("testdata", fmt.Sprintf("policy_keep_snapshots_%d", i))
|
||||
|
||||
if *updateGoldenFiles {
|
||||
buf, err := json.MarshalIndent(keep, "", " ")
|
||||
if err != nil {
|
||||
t.Fatalf("error marshaling result: %v", err)
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(goldenFilename, buf, 0644); err != nil {
|
||||
t.Fatalf("unable to update golden file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadFile(goldenFilename)
|
||||
if *updateGoldenFiles {
|
||||
buf, err := json.MarshalIndent(keep, "", " ")
|
||||
if err != nil {
|
||||
t.Fatalf("error loading golden file %v: %v", goldenFilename, err)
|
||||
t.Fatalf("error marshaling result: %v", err)
|
||||
}
|
||||
|
||||
var want restic.Snapshots
|
||||
err = json.Unmarshal(buf, &want)
|
||||
|
||||
if !reflect.DeepEqual(keep, want) {
|
||||
t.Fatalf("test %v: wrong result, want:\n %v\ngot:\n %v", i, want, keep)
|
||||
if err = ioutil.WriteFile(goldenFilename, buf, 0644); err != nil {
|
||||
t.Fatalf("unable to update golden file: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadFile(goldenFilename)
|
||||
if err != nil {
|
||||
t.Errorf("error loading golden file %v: %v", goldenFilename, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var want restic.Snapshots
|
||||
err = json.Unmarshal(buf, &want)
|
||||
|
||||
if !reflect.DeepEqual(keep, want) {
|
||||
t.Errorf("test %v: wrong result, want:\n %v\ngot:\n %v", i, want, keep)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
src/restic/testdata/policy_keep_snapshots_0
vendored
10
src/restic/testdata/policy_keep_snapshots_0
vendored
@ -120,7 +120,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-13T10:20:30Z",
|
||||
"time": "2015-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -270,7 +270,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-13T10:20:30Z",
|
||||
"time": "2015-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -324,7 +324,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2014-11-13T10:20:30Z",
|
||||
"time": "2014-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
@ -519,7 +519,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2014-08-13T10:20:30Z",
|
||||
"time": "2014-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -543,4 +543,4 @@
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
||||
]
|
2
src/restic/testdata/policy_keep_snapshots_10
vendored
2
src/restic/testdata/policy_keep_snapshots_10
vendored
@ -49,4 +49,4 @@
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
||||
]
|
2
src/restic/testdata/policy_keep_snapshots_13
vendored
2
src/restic/testdata/policy_keep_snapshots_13
vendored
@ -19,4 +19,4 @@
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
||||
]
|
2
src/restic/testdata/policy_keep_snapshots_15
vendored
2
src/restic/testdata/policy_keep_snapshots_15
vendored
@ -34,4 +34,4 @@
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
||||
]
|
2
src/restic/testdata/policy_keep_snapshots_17
vendored
2
src/restic/testdata/policy_keep_snapshots_17
vendored
@ -49,4 +49,4 @@
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
||||
]
|
2
src/restic/testdata/policy_keep_snapshots_18
vendored
2
src/restic/testdata/policy_keep_snapshots_18
vendored
@ -120,4 +120,4 @@
|
||||
"foo"
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
2
src/restic/testdata/policy_keep_snapshots_19
vendored
2
src/restic/testdata/policy_keep_snapshots_19
vendored
@ -8,4 +8,4 @@
|
||||
"bar"
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
10
src/restic/testdata/policy_keep_snapshots_3
vendored
10
src/restic/testdata/policy_keep_snapshots_3
vendored
@ -120,7 +120,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-13T10:20:30Z",
|
||||
"time": "2015-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -270,7 +270,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-13T10:20:30Z",
|
||||
"time": "2015-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -324,7 +324,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2014-11-13T10:20:30Z",
|
||||
"time": "2014-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
@ -519,7 +519,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2014-08-13T10:20:30Z",
|
||||
"time": "2014-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -543,4 +543,4 @@
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
||||
]
|
10
src/restic/testdata/policy_keep_snapshots_4
vendored
10
src/restic/testdata/policy_keep_snapshots_4
vendored
@ -120,7 +120,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-11-13T10:20:30Z",
|
||||
"time": "2015-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -270,7 +270,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2015-08-13T10:20:30Z",
|
||||
"time": "2015-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -324,7 +324,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "2014-11-13T10:20:30Z",
|
||||
"time": "2014-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null,
|
||||
"tags": [
|
||||
@ -519,7 +519,7 @@
|
||||
"paths": null
|
||||
},
|
||||
{
|
||||
"time": "2014-08-13T10:20:30Z",
|
||||
"time": "2014-08-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
@ -543,4 +543,4 @@
|
||||
"tree": 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
|
||||
},
|
||||
{
|
||||
"time": "2015-11-13T10:20:30Z",
|
||||
"time": "2015-11-13T10:20:30.1Z",
|
||||
"tree": 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
|
||||
},
|
||||
{
|
||||
"time": "2015-11-13T10:20:30Z",
|
||||
"time": "2015-11-13T10:20:30.1Z",
|
||||
"tree": null,
|
||||
"paths": null
|
||||
},
|
||||
|
2
src/restic/testdata/policy_keep_snapshots_9
vendored
2
src/restic/testdata/policy_keep_snapshots_9
vendored
@ -29,4 +29,4 @@
|
||||
"tree": null,
|
||||
"paths": null
|
||||
}
|
||||
]
|
||||
]
|
Loading…
Reference in New Issue
Block a user