From 8b22aec1bb0d69a107c6be7557311ccbb084d4b7 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 2 Nov 2026 00:30:53 +0800 Subject: [PATCH] fix(restic): drop a stale btrfs snapshot before taking a new one Cleanup runs as ExecStopPost, which a power loss mid-backup skips; the leftover @restic-snapshot then failed every later run. Assisted-by: Claude Code (claude-opus-5-5) --- modules/nixos/base/restic-backup.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/nixos/base/restic-backup.nix b/modules/nixos/base/restic-backup.nix index aa6e1bff..7c9c9739 100644 --- a/modules/nixos/base/restic-backup.nix +++ b/modules/nixos/base/restic-backup.nix @@ -200,7 +200,11 @@ in } // lib.optionalAttrs (cfg.snapshotSource != null) { + # Left behind if a backup was cut off by a power loss. backupPrepareCommand = '' + if [ -e ${snapshotPath} ]; then + ${pkgs.btrfs-progs}/bin/btrfs subvolume delete ${snapshotPath} + fi ${pkgs.btrfs-progs}/bin/btrfs subvolume snapshot -r ${cfg.snapshotSource} ${snapshotPath} ''; backupCleanupCommand = ''