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?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No 

## Type of change

- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🐹 Trivial/Minor

## Issue(s)

* #1740 

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2022-12-17 00:03:59 -08:00 committed by GitHub
parent 7a5a8c077e
commit af15eb032c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 8 deletions

View File

@ -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))

View File

@ -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,
})
})
}
}