From 743c614ce41dbadf43535ec909a710bce0231999 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Fri, 2 Dec 2022 08:25:16 -0800 Subject: [PATCH] Use previous snapshots to allow kopia to find previous versions of files (#1430) ## Description Tell kopia about previous snapshots during the backup so it can make use of them to skip uploading some data. Currently only selects the most recent completed snapshot and most recent incomplete snapshot that contains the information being backed up. This can be tuned later if it is not working good enough. However, increasing the number of previous snapshots passed in may increase memory usage during backup ## Type of change - [x] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * closes #1404 merge after: * #1427 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/conn.go | 10 ++++++++++ src/internal/kopia/snapshot_manager.go | 3 --- src/internal/kopia/wrapper.go | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/internal/kopia/conn.go b/src/internal/kopia/conn.go index 5e0d3a14d..40929987d 100644 --- a/src/internal/kopia/conn.go +++ b/src/internal/kopia/conn.go @@ -10,6 +10,7 @@ import ( "github.com/kopia/kopia/repo/blob" "github.com/kopia/kopia/repo/compression" "github.com/kopia/kopia/repo/content" + "github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot/policy" "github.com/pkg/errors" @@ -59,6 +60,8 @@ func IsRepoAlreadyExistsError(e error) bool { return errors.As(e, &erae) } +var _ snapshotManager = &conn{} + type conn struct { storage storage.Storage repo.Repository @@ -379,3 +382,10 @@ func checkCompressor(compressor compression.Name) error { return errors.Errorf("unknown compressor type %s", compressor) } + +func (w *conn) LoadSnapshots( + ctx context.Context, + ids []manifest.ID, +) ([]*snapshot.Manifest, error) { + return snapshot.LoadSnapshots(ctx, w.Repository, ids) +} diff --git a/src/internal/kopia/snapshot_manager.go b/src/internal/kopia/snapshot_manager.go index 12f768fbd..23148c3b5 100644 --- a/src/internal/kopia/snapshot_manager.go +++ b/src/internal/kopia/snapshot_manager.go @@ -187,9 +187,6 @@ func fetchPrevManifests( // incomplete. An incomplete manifest may be returned if it is newer than the // newest complete manifest for the tuple. Manifests are deduped such that if // multiple tuples match the same manifest it will only be returned once. -// -// TODO(ashmrtn): Use to get previous manifests so backup can find previously -// uploaded versions of a file. func fetchPrevSnapshotManifests( ctx context.Context, sm snapshotManager, diff --git a/src/internal/kopia/wrapper.go b/src/internal/kopia/wrapper.go index 3420cc4e0..e91cb11a3 100644 --- a/src/internal/kopia/wrapper.go +++ b/src/internal/kopia/wrapper.go @@ -530,6 +530,8 @@ func (w Wrapper) makeSnapshotWithRoot( ) (*BackupStats, error) { var man *snapshot.Manifest + prevSnaps := fetchPrevSnapshotManifests(ctx, w.c, oc) + bc := &stats.ByteCounter{} err := repo.WriteSession( @@ -569,7 +571,7 @@ func (w Wrapper) makeSnapshotWithRoot( progress.UploadProgress = u.Progress u.Progress = progress - man, err = u.Upload(innerCtx, root, policyTree, si) + man, err = u.Upload(innerCtx, root, policyTree, si, prevSnaps...) if err != nil { err = errors.Wrap(err, "uploading data") logger.Ctx(innerCtx).Errorw("kopia backup", err)