From fab4a8a4d29089e80e561670094403aa01ee184b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 14 Apr 2023 21:53:01 +0200 Subject: [PATCH 1/4] Properly initialize the --group-by option for backup tests --- cmd/restic/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index d3882116e..93162b223 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -71,6 +71,7 @@ func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts defer cleanup() } + opts.GroupBy = restic.SnapshotGroupByOptions{Host: true, Path: true} backupErr := runBackup(ctx, opts, gopts, term, target) cancel() From 2841a87cc6e37c961bf6d4b2ca2cc8b888f1a5e9 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 14 Apr 2023 21:53:55 +0200 Subject: [PATCH 2/4] Fix snapshot filtering for relative paths in the backup command The snapshot filtering internally converts relative paths to absolute ones to ensure that the parent snapshots selection works for backups of relative paths. --- internal/restic/snapshot_find.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/restic/snapshot_find.go b/internal/restic/snapshot_find.go index 4d4bb4957..8d6f8c4b1 100644 --- a/internal/restic/snapshot_find.go +++ b/internal/restic/snapshot_find.go @@ -46,6 +46,7 @@ func (f *SnapshotFilter) findLatest(ctx context.Context, be Lister, loader Loade } absTargets = append(absTargets, filepath.Clean(target)) } + f.Paths = absTargets var latest *Snapshot From ba16904eed17e62449b2b415fbfc6b049d6a9088 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 14 Apr 2023 22:21:43 +0200 Subject: [PATCH 3/4] backup: Add test to verify parent snapshot selection for relative paths --- cmd/restic/integration_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 93162b223..dbefe83a7 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -363,6 +363,28 @@ func testBackup(t *testing.T, useFsSnapshot bool) { testRunCheck(t, env.gopts) } +func TestBackupWithRelativePath(t *testing.T) { + env, cleanup := withTestEnvironment(t) + defer cleanup() + + testSetupBackupData(t, env) + opts := BackupOptions{} + + // first backup + testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, env.gopts) + snapshotIDs := testRunList(t, "snapshots", env.gopts) + rtest.Assert(t, len(snapshotIDs) == 1, "expected one snapshot, got %v", snapshotIDs) + firstSnapshotID := snapshotIDs[0] + + // second backup, implicit incremental + testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, env.gopts) + + // that the correct parent snapshot was used + latestSn, _ := testRunSnapshots(t, env.gopts) + rtest.Assert(t, latestSn != nil, "missing latest snapshot") + rtest.Assert(t, latestSn.Parent != nil && latestSn.Parent.Equal(firstSnapshotID), "second snapshot selected unexpected parent %v instead of %v", latestSn.Parent, firstSnapshotID) +} + func TestDryRunBackup(t *testing.T) { env, cleanup := withTestEnvironment(t) defer cleanup() From 3001dd8c2b759037779edad6b25fc2117ec62c3a Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 21 Apr 2023 22:35:02 +0200 Subject: [PATCH 4/4] Add test to verify that the backup parent is correctly selected --- cmd/restic/integration_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index dbefe83a7..10ebbaf13 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -385,6 +385,33 @@ func TestBackupWithRelativePath(t *testing.T) { rtest.Assert(t, latestSn.Parent != nil && latestSn.Parent.Equal(firstSnapshotID), "second snapshot selected unexpected parent %v instead of %v", latestSn.Parent, firstSnapshotID) } +func TestBackupParentSelection(t *testing.T) { + env, cleanup := withTestEnvironment(t) + defer cleanup() + + testSetupBackupData(t, env) + opts := BackupOptions{} + + // first backup + testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata/0/0"}, opts, env.gopts) + snapshotIDs := testRunList(t, "snapshots", env.gopts) + rtest.Assert(t, len(snapshotIDs) == 1, "expected one snapshot, got %v", snapshotIDs) + firstSnapshotID := snapshotIDs[0] + + // second backup, sibling path + testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata/0/tests"}, opts, env.gopts) + snapshotIDs = testRunList(t, "snapshots", env.gopts) + rtest.Assert(t, len(snapshotIDs) == 2, "expected two snapshots, got %v", snapshotIDs) + + // third backup, incremental for the first backup + testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata/0/0"}, opts, env.gopts) + + // test that the correct parent snapshot was used + latestSn, _ := testRunSnapshots(t, env.gopts) + rtest.Assert(t, latestSn != nil, "missing latest snapshot") + rtest.Assert(t, latestSn.Parent != nil && latestSn.Parent.Equal(firstSnapshotID), "third snapshot selected unexpected parent %v instead of %v", latestSn.Parent, firstSnapshotID) +} + func TestDryRunBackup(t *testing.T) { env, cleanup := withTestEnvironment(t) defer cleanup()