From 845949e8273fdc68a6bf4d65b5bf28ab88769de9 Mon Sep 17 00:00:00 2001 From: thatbagu Date: Sat, 21 Nov 2026 02:29:09 +0500 Subject: [PATCH] fix(backups): unlock the repository after a restore A restore can leave its restic lock in the repository. Every later backup then saved its snapshot but failed at "forget" ("repository is already locked"): on a live cluster, Nextcloud's backup errored on every run after a --new-cluster rebuild, and its ReplicationSource stayed Failed. nixlab-restore now sets the ReplicationSource's restic.unlock, so the next run unlocks first (VolSync's own mechanism; Argo CD leaves it). Co-Authored-By: Claude Opus 5.5 --- system/k8s/app-backups-tools.nix | 4 ++++ tests/vm/app-backups.nix | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/system/k8s/app-backups-tools.nix b/system/k8s/app-backups-tools.nix index 162e1f6..5972305 100644 --- a/system/k8s/app-backups-tools.nix +++ b/system/k8s/app-backups-tools.nix @@ -122,6 +122,10 @@ in echo "restoring ..." wait_for replicationdestination "$dest" "$now" kubectl -n "$ns" delete replicationdestination "$dest" >/dev/null + # The restore can leave its restic lock in the repository, and every + # later backup then fails at "forget" ("repository is already + # locked"): its next run unlocks first. + kubectl -n "$ns" patch replicationsource "$claim" --type merge -p "{\"spec\":{\"restic\":{\"unlock\":\"$now\"}}}" >/dev/null echo "restored $ns/$claim; starting its apps again" ''; }; diff --git a/tests/vm/app-backups.nix b/tests/vm/app-backups.nix index 24ec324..0bd069f 100644 --- a/tests/vm/app-backups.nix +++ b/tests/vm/app-backups.nix @@ -84,6 +84,11 @@ testLib.mkVmTest { { waitUntil = "${k} -n notes rollout status deploy/notes --timeout=10s"; timeout = 300; } { desc = "the backed-up contents, and the app running again"; succeed = "[ \"$(${notes} cat /data/hello)\" = backed-up ]"; } + { desc = "the next backup unlocks the repository first (a restore can leave its lock)"; + succeed = "[ -n \"$(${k} -n notes get replicationsource notes-data -o jsonpath='{.spec.restic.unlock}')\" ]"; } + { succeed = "nixlab-backup-now notes/notes-data"; timeout = 900; } + { desc = "and succeeds"; + succeed = "[ \"$(${k} -n notes get replicationsource notes-data -o jsonpath='{.status.latestMoverStatus.result}')\" = Successful ] && [ -n \"$(${k} -n notes get replicationsource notes-data -o jsonpath='{.status.restic.lastUnlocked}')\" ]"; } ]; } ];