From 526cc8fa9bca3dd3a6a2ecf26e50dbba2b6e552a Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Fri, 30 Sep 2022 16:10:10 -0700 Subject: [PATCH] Add code to disable default scheduling policy (#1010) ## Description All backups with corso are manual and use data sourced outside of kopia's control. Disable kopia's scheduling policy so we don't accidentally confuse it ## Type of change - [x] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * closes #1009 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/conn.go | 20 ++++++++++++++++++++ src/internal/kopia/conn_test.go | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/internal/kopia/conn.go b/src/internal/kopia/conn.go index 522472c01..5e0d3a14d 100644 --- a/src/internal/kopia/conn.go +++ b/src/internal/kopia/conn.go @@ -4,6 +4,7 @@ import ( "context" "path/filepath" "sync" + "time" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/repo/blob" @@ -21,6 +22,8 @@ const ( defaultKopiaConfigDir = "/tmp/" defaultKopiaConfigFile = "repository.config" defaultCompressor = "s2-default" + // Interval of 0 disables scheduling. + defaultSchedulingInterval = time.Second * 0 ) const defaultConfigErrTmpl = "setting default repo config values" @@ -237,6 +240,10 @@ func (w *conn) setDefaultConfigValues(ctx context.Context) error { changed = true } + if updateSchedulingOnPolicy(defaultSchedulingInterval, p) { + changed = true + } + if !changed { return nil } @@ -305,6 +312,19 @@ func updateRetentionOnPolicy(retention policy.RetentionPolicy, p *policy.Policy) return true } +func updateSchedulingOnPolicy( + interval time.Duration, + p *policy.Policy, +) bool { + if p.SchedulingPolicy.Interval() == interval { + return false + } + + p.SchedulingPolicy.SetInterval(interval) + + return true +} + func (w *conn) getGlobalPolicyOrEmpty(ctx context.Context) (*policy.Policy, error) { si := policy.GlobalPolicySourceInfo return w.getPolicyOrEmpty(ctx, si) diff --git a/src/internal/kopia/conn_test.go b/src/internal/kopia/conn_test.go index 66f52f017..137c58ac3 100644 --- a/src/internal/kopia/conn_test.go +++ b/src/internal/kopia/conn_test.go @@ -4,6 +4,7 @@ import ( "context" "math" "testing" + "time" "github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot/policy" @@ -260,6 +261,18 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() { newRetention := policy.RetentionPolicy{KeepDaily: &newRetentionDaily} updateRetentionOnPolicy(newRetention, p) + return nil + }, + }, + { + name: "Scheduling", + checkFunc: func(t *testing.T, p *policy.Policy) { + t.Helper() + require.Equal(t, time.Second*0, p.SchedulingPolicy.Interval()) + }, + mutator: func(innerCtx context.Context, p *policy.Policy) error { + updateSchedulingOnPolicy(time.Second*42, p) + return nil }, },