From 8d09612b811cb5ee062a802c0d766049aee74325 Mon Sep 17 00:00:00 2001 From: Keepers Date: Thu, 15 Dec 2022 20:33:24 -0700 Subject: [PATCH] correct backup tag key, metadata not found (#1830) ## Description Fixes two bugs: 1. building the correc tag key when retrieving the prior backup id from a manifest. 2. returning ErrNotFound when a snapshot entry isn't found for restore. This can occur for metadata if the service has a prior backup that does not contain the expected metadata files. ## Does this PR need a docs update or release note? - [x] :no_entry: No ## Type of change - [x] :bug: Bugfix ## Issue(s) * #1823 ## Test Plan - [x] :muscle: Manual --- src/cli/backup/onedrive.go | 2 +- src/internal/kopia/wrapper.go | 5 +++++ src/internal/operations/backup.go | 19 +++++-------------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/cli/backup/onedrive.go b/src/cli/backup/onedrive.go index 4ee03a159..6b86cc041 100644 --- a/src/cli/backup/onedrive.go +++ b/src/cli/backup/onedrive.go @@ -334,7 +334,7 @@ func oneDriveDetailsCmd() *cobra.Command { } } -// lists the history of backup operations +// prints the item details for a given backup func detailsOneDriveCmd(cmd *cobra.Command, args []string) error { ctx := cmd.Context() diff --git a/src/internal/kopia/wrapper.go b/src/internal/kopia/wrapper.go index 31a32c422..8d28c90ea 100644 --- a/src/internal/kopia/wrapper.go +++ b/src/internal/kopia/wrapper.go @@ -2,6 +2,7 @@ package kopia import ( "context" + "strings" "github.com/hashicorp/go-multierror" "github.com/kopia/kopia/fs" @@ -277,6 +278,10 @@ func getItemStream( encodeElements(itemPath.PopFront().Elements()...), ) if err != nil { + if strings.Contains(err.Error(), "entry not found") { + err = errors.Wrap(ErrNotFound, err.Error()) + } + return nil, errors.Wrap(err, "getting nested object handle") } diff --git a/src/internal/operations/backup.go b/src/internal/operations/backup.go index 7bfea16c5..6a5a205d1 100644 --- a/src/internal/operations/backup.go +++ b/src/internal/operations/backup.go @@ -211,26 +211,19 @@ func produceManifestsAndMetadata( continue } - bup := backup.Backup{} + k, _ := kopia.MakeTagKV(kopia.TagBackupID) + bupID := man.Tags[k] - if err := sw.Get( - ctx, - model.BackupSchema, - model.StableID(man.Tags[kopia.TagBackupID]), - &bup, - ); err != nil { + bup, err := sw.GetBackup(ctx, model.StableID(bupID)) + if err != nil { return nil, nil, err } colls, err := collectMetadata(ctx, kw, graph.MetadataFileNames(), oc, tid, bup.SnapshotID) - if err != nil { + if err != nil && !errors.Is(err, kopia.ErrNotFound) { // prior metadata isn't guaranteed to exist. // if it doesn't, we'll just have to do a // full backup for that data. - if errors.Is(err, errNotRestored) { - continue - } - return nil, nil, err } @@ -240,8 +233,6 @@ func produceManifestsAndMetadata( return ms, collections, err } -var errNotRestored = errors.New("unable to restore metadata") - func collectMetadata( ctx context.Context, kw *kopia.Wrapper,