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

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🐹 Trivial/Minor

## Issue(s)

* closes #1009

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2022-09-30 16:10:10 -07:00 committed by GitHub
parent 5e4b823663
commit 526cc8fa9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

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

View File

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