diff --git a/src/restic/archiver/archive_reader.go b/src/restic/archiver/archive_reader.go index fb3803e34..df912e09c 100644 --- a/src/restic/archiver/archive_reader.go +++ b/src/restic/archiver/archive_reader.go @@ -13,9 +13,9 @@ import ( // ArchiveReader reads from the reader and archives the data. Returned is the // resulting snapshot and its ID. -func ArchiveReader(repo restic.Repository, p *restic.Progress, rd io.Reader, name string) (*restic.Snapshot, restic.ID, error) { +func ArchiveReader(repo restic.Repository, p *restic.Progress, rd io.Reader, name string, tags []string) (*restic.Snapshot, restic.ID, error) { debug.Log("ArchiveReader", "start archiving %s", name) - sn, err := restic.NewSnapshot([]string{name}) + sn, err := restic.NewSnapshot([]string{name}, tags) if err != nil { return nil, restic.ID{}, err } diff --git a/src/restic/archiver/archiver.go b/src/restic/archiver/archiver.go index 3be272adc..565f15baa 100644 --- a/src/restic/archiver/archiver.go +++ b/src/restic/archiver/archiver.go @@ -633,7 +633,7 @@ func (p baseNameSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // Snapshot creates a snapshot of the given paths. If parentrestic.ID is set, this is // used to compare the files to the ones archived at the time this snapshot was // taken. -func (arch *Archiver) Snapshot(p *restic.Progress, paths []string, parentID *restic.ID) (*restic.Snapshot, restic.ID, error) { +func (arch *Archiver) Snapshot(p *restic.Progress, paths, tags []string, parentID *restic.ID) (*restic.Snapshot, restic.ID, error) { paths = unique(paths) sort.Sort(baseNameSlice(paths)) @@ -649,7 +649,7 @@ func (arch *Archiver) Snapshot(p *restic.Progress, paths []string, parentID *res defer p.Done() // create new snapshot - sn, err := restic.NewSnapshot(paths) + sn, err := restic.NewSnapshot(paths, tags) if err != nil { return nil, restic.ID{}, err } diff --git a/src/restic/archiver/testing.go b/src/restic/archiver/testing.go index b73f09dcd..fef61f6c2 100644 --- a/src/restic/archiver/testing.go +++ b/src/restic/archiver/testing.go @@ -8,7 +8,7 @@ import ( // TestSnapshot creates a new snapshot of path. func TestSnapshot(t testing.TB, repo restic.Repository, path string, parent *restic.ID) *restic.Snapshot { arch := New(repo) - sn, _, err := arch.Snapshot(nil, []string{path}, parent) + sn, _, err := arch.Snapshot(nil, []string{path}, []string{"test"}, parent) if err != nil { t.Fatal(err) } diff --git a/src/restic/snapshot.go b/src/restic/snapshot.go index dc351e8e4..0ad507181 100644 --- a/src/restic/snapshot.go +++ b/src/restic/snapshot.go @@ -21,13 +21,14 @@ type Snapshot struct { UID uint32 `json:"uid,omitempty"` GID uint32 `json:"gid,omitempty"` Excludes []string `json:"excludes,omitempty"` + Tags []string `json:"tags,omitempty"` id *ID // plaintext ID, used during restore } // NewSnapshot returns an initialized snapshot struct for the current user and // time. -func NewSnapshot(paths []string) (*Snapshot, error) { +func NewSnapshot(paths []string, tags []string) (*Snapshot, error) { for i, path := range paths { if p, err := filepath.Abs(path); err != nil { paths[i] = p @@ -37,6 +38,7 @@ func NewSnapshot(paths []string) (*Snapshot, error) { sn := &Snapshot{ Paths: paths, Time: time.Now(), + Tags: tags, } hn, err := os.Hostname() diff --git a/src/restic/snapshot_filter.go b/src/restic/snapshot_filter.go index 595987d95..2abc69343 100644 --- a/src/restic/snapshot_filter.go +++ b/src/restic/snapshot_filter.go @@ -31,6 +31,22 @@ type SnapshotFilter struct { Hostname string Username string Paths []string + Tags []string +} + +func hasTags(have, want []string) bool { +nextTag: + for _, tag := range want { + for _, snTag := range have { + if tag == snTag { + continue nextTag + } + } + + return false + } + + return true } // FilterSnapshots returns the snapshots from s which match the filter f. @@ -48,6 +64,10 @@ func FilterSnapshots(s Snapshots, f SnapshotFilter) (result Snapshots) { continue } + if !hasTags(snap.Tags, f.Tags) { + continue + } + result = append(result, snap) } diff --git a/src/restic/snapshot_filter_test.go b/src/restic/snapshot_filter_test.go index 6c5397a4f..000544977 100644 --- a/src/restic/snapshot_filter_test.go +++ b/src/restic/snapshot_filter_test.go @@ -22,25 +22,25 @@ func parseTimeUTC(s string) time.Time { } var testFilterSnapshots = restic.Snapshots{ - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-01 01:02:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "bar", Username: "testuser", Time: parseTimeUTC("2016-01-01 01:03:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-03 07:02:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "bar", Username: "testuser", Time: parseTimeUTC("2016-01-01 07:08:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 10:23:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 11:23:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:23:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:24:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:28:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:30:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 16:23:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-05 09:02:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-06 08:02:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-07 10:02:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "root", Time: parseTimeUTC("2016-01-08 20:02:03"), Paths: []string{"/usr", "/sbin"}}, - {Hostname: "foo", Username: "root", Time: parseTimeUTC("2016-01-09 21:02:03"), Paths: []string{"/usr", "/sbin"}}, - {Hostname: "bar", Username: "root", Time: parseTimeUTC("2016-01-12 21:02:03"), Paths: []string{"/usr", "/sbin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-12 21:08:03"), Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-18 12:02:03"), Paths: []string{"/usr", "/bin"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-01 01:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "bar", Username: "testuser", Time: parseTimeUTC("2016-01-01 01:03:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-03 07:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "bar", Username: "testuser", Time: parseTimeUTC("2016-01-01 07:08:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 10:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 11:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:24:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:28:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:30:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test", "foo", "bar"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 16:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test", "test2"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-05 09:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-06 08:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"fox"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-07 10:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"fox"}}, + {Hostname: "foo", Username: "root", Time: parseTimeUTC("2016-01-08 20:02:03"), Paths: []string{"/usr", "/sbin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "root", Time: parseTimeUTC("2016-01-09 21:02:03"), Paths: []string{"/usr", "/sbin"}, Tags: []string{"fox"}}, + {Hostname: "bar", Username: "root", Time: parseTimeUTC("2016-01-12 21:02:03"), Paths: []string{"/usr", "/sbin"}, Tags: []string{"foo"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-12 21:08:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"bar"}}, + {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-18 12:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"bar"}}, } var filterTests = []restic.SnapshotFilter{ @@ -50,6 +50,10 @@ var filterTests = []restic.SnapshotFilter{ {Paths: []string{"/usr", "/bin"}}, {Hostname: "bar", Paths: []string{"/usr", "/bin"}}, {Hostname: "foo", Username: "root", Paths: []string{"/usr", "/sbin"}}, + {Tags: []string{"foo"}}, + {Tags: []string{"fox"}, Username: "root"}, + {Tags: []string{"foo", "test"}}, + {Tags: []string{"foo", "test2"}}, } func TestFilterSnapshots(t *testing.T) { diff --git a/src/restic/snapshot_test.go b/src/restic/snapshot_test.go index 35474eb2b..2457e8d65 100644 --- a/src/restic/snapshot_test.go +++ b/src/restic/snapshot_test.go @@ -10,6 +10,6 @@ import ( func TestNewSnapshot(t *testing.T) { paths := []string{"/home/foobar"} - _, err := restic.NewSnapshot(paths) + _, err := restic.NewSnapshot(paths, nil) OK(t, err) } diff --git a/src/restic/testdata/filter_snapshots_0 b/src/restic/testdata/filter_snapshots_0 index 4afbe3b55..324bcaa00 100644 --- a/src/restic/testdata/filter_snapshots_0 +++ b/src/restic/testdata/filter_snapshots_0 @@ -7,7 +7,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "bar" + ] }, { "time": "2016-01-12T21:08:03Z", @@ -17,7 +20,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "bar" + ] }, { "time": "2016-01-09T21:02:03Z", @@ -27,7 +33,10 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "fox" + ] }, { "time": "2016-01-08T20:02:03Z", @@ -37,7 +46,10 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "foo" + ] }, { "time": "2016-01-07T10:02:03Z", @@ -47,7 +59,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "fox" + ] }, { "time": "2016-01-06T08:02:03Z", @@ -57,7 +72,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "fox" + ] }, { "time": "2016-01-05T09:02:03Z", @@ -67,7 +85,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-04T16:23:03Z", @@ -77,7 +98,11 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test", + "test2" + ] }, { "time": "2016-01-04T12:30:03Z", @@ -87,7 +112,12 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test", + "foo", + "bar" + ] }, { "time": "2016-01-04T12:28:03Z", @@ -97,7 +127,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test" + ] }, { "time": "2016-01-04T12:24:03Z", @@ -107,7 +140,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test" + ] }, { "time": "2016-01-04T12:23:03Z", @@ -117,7 +153,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-04T11:23:03Z", @@ -127,7 +166,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-04T10:23:03Z", @@ -137,7 +179,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-03T07:02:03Z", @@ -147,7 +192,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-01T01:02:03Z", @@ -157,6 +205,9 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] } ] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_1 b/src/restic/testdata/filter_snapshots_1 index c9bd44ddc..f219dcc7c 100644 --- a/src/restic/testdata/filter_snapshots_1 +++ b/src/restic/testdata/filter_snapshots_1 @@ -7,7 +7,10 @@ "/sbin" ], "hostname": "bar", - "username": "root" + "username": "root", + "tags": [ + "foo" + ] }, { "time": "2016-01-09T21:02:03Z", @@ -17,7 +20,10 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "fox" + ] }, { "time": "2016-01-08T20:02:03Z", @@ -27,6 +33,9 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "foo" + ] } ] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_2 b/src/restic/testdata/filter_snapshots_2 index cae5b39e7..f070335e1 100644 --- a/src/restic/testdata/filter_snapshots_2 +++ b/src/restic/testdata/filter_snapshots_2 @@ -7,7 +7,10 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "fox" + ] }, { "time": "2016-01-08T20:02:03Z", @@ -17,6 +20,9 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "foo" + ] } ] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_3 b/src/restic/testdata/filter_snapshots_3 index d30f4bf37..c3fff0936 100644 --- a/src/restic/testdata/filter_snapshots_3 +++ b/src/restic/testdata/filter_snapshots_3 @@ -7,7 +7,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "bar" + ] }, { "time": "2016-01-12T21:08:03Z", @@ -17,7 +20,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "bar" + ] }, { "time": "2016-01-07T10:02:03Z", @@ -27,7 +33,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "fox" + ] }, { "time": "2016-01-06T08:02:03Z", @@ -37,7 +46,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "fox" + ] }, { "time": "2016-01-05T09:02:03Z", @@ -47,7 +59,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-04T16:23:03Z", @@ -57,7 +72,11 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test", + "test2" + ] }, { "time": "2016-01-04T12:30:03Z", @@ -67,7 +86,12 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test", + "foo", + "bar" + ] }, { "time": "2016-01-04T12:28:03Z", @@ -77,7 +101,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test" + ] }, { "time": "2016-01-04T12:24:03Z", @@ -87,7 +114,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "test" + ] }, { "time": "2016-01-04T12:23:03Z", @@ -97,7 +127,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-04T11:23:03Z", @@ -107,7 +140,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-04T10:23:03Z", @@ -117,7 +153,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-03T07:02:03Z", @@ -127,7 +166,10 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-01T07:08:03Z", @@ -137,7 +179,10 @@ "/bin" ], "hostname": "bar", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-01T01:03:03Z", @@ -147,7 +192,10 @@ "/bin" ], "hostname": "bar", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-01T01:02:03Z", @@ -157,6 +205,9 @@ "/bin" ], "hostname": "foo", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] } ] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_4 b/src/restic/testdata/filter_snapshots_4 index a334bbcb6..4719ddd59 100644 --- a/src/restic/testdata/filter_snapshots_4 +++ b/src/restic/testdata/filter_snapshots_4 @@ -7,7 +7,10 @@ "/bin" ], "hostname": "bar", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] }, { "time": "2016-01-01T01:03:03Z", @@ -17,6 +20,9 @@ "/bin" ], "hostname": "bar", - "username": "testuser" + "username": "testuser", + "tags": [ + "foo" + ] } ] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_5 b/src/restic/testdata/filter_snapshots_5 index cae5b39e7..f070335e1 100644 --- a/src/restic/testdata/filter_snapshots_5 +++ b/src/restic/testdata/filter_snapshots_5 @@ -7,7 +7,10 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "fox" + ] }, { "time": "2016-01-08T20:02:03Z", @@ -17,6 +20,9 @@ "/sbin" ], "hostname": "foo", - "username": "root" + "username": "root", + "tags": [ + "foo" + ] } ] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_6 b/src/restic/testdata/filter_snapshots_6 new file mode 100644 index 000000000..c711171b7 --- /dev/null +++ b/src/restic/testdata/filter_snapshots_6 @@ -0,0 +1,147 @@ +[ + { + "time": "2016-01-12T21:02:03Z", + "tree": null, + "paths": [ + "/usr", + "/sbin" + ], + "hostname": "bar", + "username": "root", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-08T20:02:03Z", + "tree": null, + "paths": [ + "/usr", + "/sbin" + ], + "hostname": "foo", + "username": "root", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-05T09:02:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-04T12:30:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "test", + "foo", + "bar" + ] + }, + { + "time": "2016-01-04T12:23:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-04T11:23:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-04T10:23:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-03T07:02:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-01T07:08:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "bar", + "username": "testuser", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-01T01:03:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "bar", + "username": "testuser", + "tags": [ + "foo" + ] + }, + { + "time": "2016-01-01T01:02:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "foo" + ] + } +] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_7 b/src/restic/testdata/filter_snapshots_7 new file mode 100644 index 000000000..bb0924dbe --- /dev/null +++ b/src/restic/testdata/filter_snapshots_7 @@ -0,0 +1,15 @@ +[ + { + "time": "2016-01-09T21:02:03Z", + "tree": null, + "paths": [ + "/usr", + "/sbin" + ], + "hostname": "foo", + "username": "root", + "tags": [ + "fox" + ] + } +] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_8 b/src/restic/testdata/filter_snapshots_8 new file mode 100644 index 000000000..fbff1e883 --- /dev/null +++ b/src/restic/testdata/filter_snapshots_8 @@ -0,0 +1,17 @@ +[ + { + "time": "2016-01-04T12:30:03Z", + "tree": null, + "paths": [ + "/usr", + "/bin" + ], + "hostname": "foo", + "username": "testuser", + "tags": [ + "test", + "foo", + "bar" + ] + } +] \ No newline at end of file diff --git a/src/restic/testdata/filter_snapshots_9 b/src/restic/testdata/filter_snapshots_9 new file mode 100644 index 000000000..ec747fa47 --- /dev/null +++ b/src/restic/testdata/filter_snapshots_9 @@ -0,0 +1 @@ +null \ No newline at end of file diff --git a/src/restic/testing.go b/src/restic/testing.go index 039b908f7..49a848965 100644 --- a/src/restic/testing.go +++ b/src/restic/testing.go @@ -154,7 +154,7 @@ func TestCreateSnapshot(t testing.TB, repo Repository, at time.Time, depth int, t.Logf("create fake snapshot at %s with seed %d", at, seed) fakedir := fmt.Sprintf("fakedir-at-%v", at.Format("2006-01-02 15:04:05")) - snapshot, err := NewSnapshot([]string{fakedir}) + snapshot, err := NewSnapshot([]string{fakedir}, []string{"test"}) if err != nil { t.Fatal(err) }