From af15eb032c21844bb90db38668f21f355e0a7f25 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Sat, 17 Dec 2022 00:03:59 -0800 Subject: [PATCH] Reuse base snapshots (#1831) ## Description During BackupCollections, use the base snapshots that were passed in from the BackupOp in the kopia uploader instead of fetching our own set of base snapshots. This will ensure the set of base snapshots is consistent throughout the backup. ## Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No ## Type of change - [x] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * #1740 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/wrapper.go | 21 ++++++++++++++------- src/internal/kopia/wrapper_test.go | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/internal/kopia/wrapper.go b/src/internal/kopia/wrapper.go index de32336d6..c56ccb525 100644 --- a/src/internal/kopia/wrapper.go +++ b/src/internal/kopia/wrapper.go @@ -110,8 +110,6 @@ func (w *Wrapper) Close(ctx context.Context) error { // from as well as any incomplete snapshot checkpoints that may contain more // recent data than the base snapshot. The absence of previousSnapshots causes a // complete backup of all data. -// -// TODO(ashmrtn): Use previousSnapshots parameter. func (w Wrapper) BackupCollections( ctx context.Context, previousSnapshots []*ManifestEntry, @@ -136,12 +134,21 @@ func (w Wrapper) BackupCollections( deets: &details.Details{}, } + // TODO(ashmrtn): Pass previousSnapshots here to enable building the directory + // hierarchy with them. dirTree, err := inflateDirTree(ctx, w.c, nil, collections, progress) if err != nil { return nil, nil, errors.Wrap(err, "building kopia directories") } - s, err := w.makeSnapshotWithRoot(ctx, dirTree, oc, progress, tags) + s, err := w.makeSnapshotWithRoot( + ctx, + previousSnapshots, + dirTree, + oc, + tags, + progress, + ) if err != nil { return nil, nil, err } @@ -151,15 +158,15 @@ func (w Wrapper) BackupCollections( func (w Wrapper) makeSnapshotWithRoot( ctx context.Context, + prevSnapEntries []*ManifestEntry, root fs.Directory, oc *OwnersCats, - progress *corsoProgress, addlTags map[string]string, + progress *corsoProgress, ) (*BackupStats, error) { var ( - man *snapshot.Manifest - prevSnapEntries = fetchPrevSnapshotManifests(ctx, w.c, oc, nil) - bc = &stats.ByteCounter{} + man *snapshot.Manifest + bc = &stats.ByteCounter{} ) prevSnaps := make([]*snapshot.Manifest, 0, len(prevSnapEntries)) diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index 83651f392..feb2c1b7d 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -262,11 +262,13 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections() { }, } + prevSnaps := []*ManifestEntry{} + for _, test := range table { suite.T().Run(test.name, func(t *testing.T) { stats, deets, err := suite.w.BackupCollections( suite.ctx, - nil, + prevSnaps, collections, path.ExchangeService, oc, @@ -295,6 +297,19 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections() { expectedTags, stats.SnapshotID, ) + + snap, err := snapshot.LoadSnapshot( + suite.ctx, + suite.w.c, + manifest.ID(stats.SnapshotID), + ) + require.NoError(t, err) + + prevSnaps = append(prevSnaps, &ManifestEntry{ + // Will need to fill out reason if/when we use this test with + // incrementals. + Manifest: snap, + }) }) } }