scheduler: clear stale restic locks before backup

This commit is contained in:
codex 2026-07-14 15:55:22 -03:00
parent ad0109305a
commit 2c733d3953
3 changed files with 3 additions and 3 deletions

View File

@ -82,7 +82,7 @@ func TestJobNameBackupCommandAndResticEnvCoverRemainingBranches(t *testing.T) {
Dedupe: &dedupe, Dedupe: &dedupe,
KeepLast: &keepLast, KeepLast: &keepLast,
}) })
if !strings.Contains(cmd, "restic init") || !strings.Contains(cmd, "--tag dedupe=off") || !strings.Contains(cmd, "--keep-last 3") { if !strings.Contains(cmd, "restic unlock") || !strings.Contains(cmd, "restic init") || !strings.Contains(cmd, "--tag dedupe=off") || !strings.Contains(cmd, "--keep-last 3") {
t.Fatalf("expected backup command to include bootstrap/dedupe/keep-last logic, got %q", cmd) t.Fatalf("expected backup command to include bootstrap/dedupe/keep-last logic, got %q", cmd)
} }
if !strings.Contains(cmd, "--exclude *.tmp") || !strings.Contains(cmd, "--tag nightly") || !strings.Contains(cmd, "--tag prod") { if !strings.Contains(cmd, "--exclude *.tmp") || !strings.Contains(cmd, "--tag nightly") || !strings.Contains(cmd, "--tag prod") {

View File

@ -206,7 +206,7 @@ func backupCommand(cfg *config.Config, req api.BackupRequest) string {
cmd = fmt.Sprintf("%s && %s", cmd, forget) cmd = fmt.Sprintf("%s && %s", cmd, forget)
} }
bootstrap := "restic snapshots >/dev/null 2>&1 || restic init" bootstrap := "restic unlock >/dev/null 2>&1 || true; restic snapshots >/dev/null 2>&1 || restic init"
return "set -euo pipefail; " + bootstrap + "; " + cmd return "set -euo pipefail; " + bootstrap + "; " + cmd
} }

View File

@ -49,7 +49,7 @@ func TestBuildBackupJobAppliesSelectorsServiceAccountAndMetadata(t *testing.T) {
if container.Name != "restic" || container.Image != "restic/restic:latest" { if container.Name != "restic" || container.Image != "restic/restic:latest" {
t.Fatalf("expected restic container, got %#v", container) t.Fatalf("expected restic container, got %#v", container)
} }
if len(container.Args) != 1 || !strings.Contains(container.Args[0], "restic backup /data") || !strings.Contains(container.Args[0], "--keep-last 3") { if len(container.Args) != 1 || !strings.Contains(container.Args[0], "restic unlock") || !strings.Contains(container.Args[0], "restic backup /data") || !strings.Contains(container.Args[0], "--keep-last 3") {
t.Fatalf("expected backup command payload, got %#v", container.Args) t.Fatalf("expected backup command payload, got %#v", container.Args)
} }
if len(job.Spec.Template.Spec.Volumes) != 2 || job.Spec.Template.Spec.Volumes[0].PersistentVolumeClaim == nil { if len(job.Spec.Template.Spec.Volumes) != 2 || job.Spec.Template.Spec.Volumes[0].PersistentVolumeClaim == nil {