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:
parent
5e4b823663
commit
526cc8fa9b
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo"
|
"github.com/kopia/kopia/repo"
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
@ -21,6 +22,8 @@ const (
|
|||||||
defaultKopiaConfigDir = "/tmp/"
|
defaultKopiaConfigDir = "/tmp/"
|
||||||
defaultKopiaConfigFile = "repository.config"
|
defaultKopiaConfigFile = "repository.config"
|
||||||
defaultCompressor = "s2-default"
|
defaultCompressor = "s2-default"
|
||||||
|
// Interval of 0 disables scheduling.
|
||||||
|
defaultSchedulingInterval = time.Second * 0
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultConfigErrTmpl = "setting default repo config values"
|
const defaultConfigErrTmpl = "setting default repo config values"
|
||||||
@ -237,6 +240,10 @@ func (w *conn) setDefaultConfigValues(ctx context.Context) error {
|
|||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if updateSchedulingOnPolicy(defaultSchedulingInterval, p) {
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
|
||||||
if !changed {
|
if !changed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -305,6 +312,19 @@ func updateRetentionOnPolicy(retention policy.RetentionPolicy, p *policy.Policy)
|
|||||||
return true
|
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) {
|
func (w *conn) getGlobalPolicyOrEmpty(ctx context.Context) (*policy.Policy, error) {
|
||||||
si := policy.GlobalPolicySourceInfo
|
si := policy.GlobalPolicySourceInfo
|
||||||
return w.getPolicyOrEmpty(ctx, si)
|
return w.getPolicyOrEmpty(ctx, si)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/kopia/kopia/snapshot"
|
"github.com/kopia/kopia/snapshot"
|
||||||
"github.com/kopia/kopia/snapshot/policy"
|
"github.com/kopia/kopia/snapshot/policy"
|
||||||
@ -260,6 +261,18 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
|
|||||||
newRetention := policy.RetentionPolicy{KeepDaily: &newRetentionDaily}
|
newRetention := policy.RetentionPolicy{KeepDaily: &newRetentionDaily}
|
||||||
updateRetentionOnPolicy(newRetention, p)
|
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
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user