From e4e4bae850d3d52a86968cd30e459ecdacd3953c Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:55:58 -0800 Subject: [PATCH] Add a pin to kopia snapshots so they won't be GCed by kopia accidentally (#5090) Internally kopia has the notion of a retention policy. This adds a pin to each snapshot that corso uses kopia to create so that those snapshots won't be subject to kopia's rentention policy. As we disable kopia's retention policy during repo init this just acts as another layer of security to ensure snapshots won't be deleted unexpectedly. Note that this PR only applies to _new_ snapshots that corso creates. It doesn't go back and pin older snapshots for already existing backups --- #### 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 - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/wrapper.go | 6 ++++++ src/internal/kopia/wrapper_test.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/internal/kopia/wrapper.go b/src/internal/kopia/wrapper.go index 592fcbdf6..b569d9779 100644 --- a/src/internal/kopia/wrapper.go +++ b/src/internal/kopia/wrapper.go @@ -34,6 +34,8 @@ import ( "github.com/alcionai/corso/src/pkg/store" ) +const defaultCorsoPin = "corso" + // common manifest tags const ( TagBackupID = "backup-id" @@ -392,6 +394,10 @@ func (w Wrapper) makeSnapshotWithRoot( } man.Tags = tags + // Add one pin to keep kopia's retention policy from collecting it if it + // ends up enabled for some reason. The value in the pin doesn't matter. + // We don't need to remove any pins. + man.UpdatePins(append(man.Pins, defaultCorsoPin), nil) if _, err := snapshot.SaveSnapshot(innerCtx, rw, man); err != nil { err = clues.WrapWC(ctx, err, "saving snapshot") diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index 922305f89..32591e2f5 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -1151,6 +1151,8 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections() { manifest.ID(stats.SnapshotID)) require.NoError(t, err, clues.ToCore(err)) + assert.Contains(t, snap.Pins, defaultCorsoPin) + man = snap })