Skip to content

Commit

Permalink
fix: forget operations failing with new retention policy format
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Mar 19, 2024
1 parent 1fc0c95 commit 0a059bb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 1 addition & 2 deletions internal/orchestrator/taskbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions internal/protoutil/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion pkg/restic/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions webui/src/components/OperationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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> */}
</>,
},
]}
Expand Down

0 comments on commit 0a059bb

Please sign in to comment.