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?

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

#### Type of change

- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2024-01-24 13:55:58 -08:00 committed by GitHub
parent cb4006eb60
commit e4e4bae850
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

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

View File

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