From 7b44fd0f9db5290682754f15184df408b471c6bd Mon Sep 17 00:00:00 2001 From: Felix Lee Date: Thu, 5 Oct 2017 11:48:26 -0700 Subject: [PATCH] fix #1143 Backup was choosing a parent snapshot that had the same tags, which makes backup unnecessarily slow when there are newer snapshots with different tags. There's no reason parent has to have the same tags. This change makes backup choose the newest snapshot instead. --- cmd/restic/cmd_backup.go | 2 +- cmd/restic/integration_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 0c254738a..f79163783 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -416,7 +416,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error { // Find last snapshot to set it as parent, if not already set if !opts.Force && parentSnapshotID == nil { - id, err := restic.FindLatestSnapshot(context.TODO(), repo, target, []restic.TagList{opts.Tags}, opts.Hostname) + id, err := restic.FindLatestSnapshot(context.TODO(), repo, target, []restic.TagList{}, opts.Hostname) if err == nil { parentSnapshotID = &id } else if err != restic.ErrNoSnapshotFound { diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index f83dd3c5c..dbc48703e 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -656,6 +656,7 @@ func TestBackupTags(t *testing.T) { rtest.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, len(newest.Tags) == 0, "expected no tags, got %v", newest.Tags) + parent := newest opts.Tags = []string{"NL"} testRunBackup(t, []string{env.testdata}, opts, env.gopts) @@ -664,6 +665,9 @@ func TestBackupTags(t *testing.T) { rtest.Assert(t, newest != nil, "expected a new backup, got nil") rtest.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL", "expected one NL tag, got %v", newest.Tags) + // Tagged backup should have untagged backup as parent. + rtest.Assert(t, parent.ID.Equal(*newest.Parent), + "expected parent to be %v, got %v", parent.ID, newest.Parent) } func testRunTag(t testing.TB, opts TagOptions, gopts GlobalOptions) {