fix: forget operations failing with new retention policy format

This commit is contained in:
garethgeorge
2024-03-19 09:50:57 -07:00
parent 1fc0c95359
commit 0a059bbb39
4 changed files with 23 additions and 5 deletions
+1 -2
View File
@@ -13,7 +13,6 @@ import (
"github.com/garethgeorge/backrest/pkg/restic"
"github.com/gitploy-io/cronexpr"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
)
var maxBackupErrorHistoryLength = 20 // arbitrary limit on the number of file read errors recorded in a backup operation to prevent it from growing too large.
@@ -186,7 +185,7 @@ func backupHelper(ctx context.Context, t Task, orchestrator *Orchestrator, plan
// schedule followup tasks
at := time.Now()
if plan.Retention != nil && !proto.Equal(plan.Retention, &v1.RetentionPolicy{}) {
if _, ok := plan.Retention.GetPolicy().(*v1.RetentionPolicy_PolicyKeepAll); plan.Retention != nil && !ok {
orchestrator.ScheduleTask(NewOneoffForgetTask(orchestrator, plan, op.SnapshotId, at), TaskPriorityForget)
}
orchestrator.ScheduleTask(NewOneoffIndexSnapshotsTask(orchestrator, plan.Repo, at), TaskPriorityIndexSnapshots)
+19
View File
@@ -88,6 +88,25 @@ func BackupProgressEntryToBackupError(b *restic.BackupProgressEntry) (*v1.Backup
}
func RetentionPolicyFromProto(p *v1.RetentionPolicy) *restic.RetentionPolicy {
if p.Policy != nil {
switch p := p.Policy.(type) {
case *v1.RetentionPolicy_PolicyKeepAll:
return nil
case *v1.RetentionPolicy_PolicyTimeBucketed:
return &restic.RetentionPolicy{
KeepDaily: int(p.PolicyTimeBucketed.Daily),
KeepHourly: int(p.PolicyTimeBucketed.Hourly),
KeepWeekly: int(p.PolicyTimeBucketed.Weekly),
KeepMonthly: int(p.PolicyTimeBucketed.Monthly),
KeepYearly: int(p.PolicyTimeBucketed.Yearly),
}
case *v1.RetentionPolicy_PolicyKeepLastN:
return &restic.RetentionPolicy{
KeepLastN: int(p.PolicyKeepLastN),
}
}
}
return &restic.RetentionPolicy{
KeepLastN: int(p.KeepLastN),
KeepHourly: int(p.KeepHourly),
+1 -1
View File
@@ -37,7 +37,7 @@ func NewRepo(resticBin string, uri string, opts ...GenericOption) *Repo {
if slices.IndexFunc(opt.extraArgs, func(a string) bool {
return strings.Contains(a, "sftp.args")
}) == -1 {
opt.extraArgs = append(opt.extraArgs, "-o", "sftp.args=-oBatchMode=yes")
// opt.extraArgs = append(opt.extraArgs, "-o", "sftp.args=-oBatchMode=yes")
}
opt.extraEnv = append(opt.extraEnv, "RESTIC_REPOSITORY="+uri)
+2 -2
View File
@@ -377,12 +377,12 @@ const ForgetOperationDetails = ({ forgetOp }: { forgetOp: OperationForget }) =>
{"removed snapshot " + normalizeSnapshotId(f.id!) + " taken at " + formatTime(Number(f.unixTimeMs))} <br />
</div>
))}</pre>
Policy:
{/* Policy:
<ul>
{policyDesc.map((desc, idx) => (
<li key={idx}>{desc}</li>
))}
</ul>
</ul> */}
</>,
},
]}