From 0a059bbb39ea6d5f6f989cc4a4541ec8aedbc071 Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Tue, 19 Mar 2024 09:50:57 -0700 Subject: [PATCH] fix: forget operations failing with new retention policy format --- internal/orchestrator/taskbackup.go | 3 +-- internal/protoutil/conversion.go | 19 +++++++++++++++++++ pkg/restic/restic.go | 2 +- webui/src/components/OperationRow.tsx | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/internal/orchestrator/taskbackup.go b/internal/orchestrator/taskbackup.go index e92fc760..69ae6e03 100644 --- a/internal/orchestrator/taskbackup.go +++ b/internal/orchestrator/taskbackup.go @@ -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) diff --git a/internal/protoutil/conversion.go b/internal/protoutil/conversion.go index d7b7b471..e1b91a96 100644 --- a/internal/protoutil/conversion.go +++ b/internal/protoutil/conversion.go @@ -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), diff --git a/pkg/restic/restic.go b/pkg/restic/restic.go index 0b0f6d7f..3c47800c 100644 --- a/pkg/restic/restic.go +++ b/pkg/restic/restic.go @@ -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) diff --git a/webui/src/components/OperationRow.tsx b/webui/src/components/OperationRow.tsx index 63a60632..9b5f079e 100644 --- a/webui/src/components/OperationRow.tsx +++ b/webui/src/components/OperationRow.tsx @@ -377,12 +377,12 @@ const ForgetOperationDetails = ({ forgetOp }: { forgetOp: OperationForget }) => {"removed snapshot " + normalizeSnapshotId(f.id!) + " taken at " + formatTime(Number(f.unixTimeMs))}
))} - Policy: + {/* Policy: + */} , }, ]}