From 5928e539fb8a259bf6b8e0d5ea5cec90be7d03b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Schr=C3=B6ter?= <dev@felschr.com> Date: Fri, 21 Jul 2023 16:14:43 +0200 Subject: [PATCH] fix(restic): cleanup stale locks before running backups --- services/restic/home-pc.nix | 15 ++++++++------- services/restic/home-server.nix | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/restic/home-pc.nix b/services/restic/home-pc.nix index 859c1c9..ac301c7 100644 --- a/services/restic/home-pc.nix +++ b/services/restic/home-pc.nix @@ -94,14 +94,15 @@ in { ]; timerConfig.OnCalendar = "0/6:00:00"; extraPruneOpts = [ "--keep-last 4" ]; - }; - # Extra handling for dev folder to respect .gitignore files. - # Do not delete `~/dev-backup` since this leads to changing ctimes - # which would cause otherwise unchanged files to be backed up again. - # Since `--link-dest` is used, file contents won't be duplicated on disk. - systemd.services."restic-backups-full" = { - preStart = '' + # Extra handling for dev folder to respect .gitignore files. + # Do not delete `~/dev-backup` since this leads to changing ctimes + # which would cause otherwise unchanged files to be backed up again. + # Since `--link-dest` is used, file contents won't be duplicated on disk. + backupPrepareCommand = '' + # remove stale locks + ${pkgs.restic}/bin/restic unlock || true + rm -rf /home/felschr/dev-backup ${pkgs.rsync}/bin/rsync \ -a --delete \ diff --git a/services/restic/home-server.nix b/services/restic/home-server.nix index d6ef279..ebd731f 100644 --- a/services/restic/home-server.nix +++ b/services/restic/home-server.nix @@ -41,5 +41,9 @@ in { ]; timerConfig.OnCalendar = "0/6:00:00"; extraPruneOpts = [ "--keep-last 4" ]; + backupPrepareCommand = '' + # remove stale locks + ${pkgs.restic}/bin/restic unlock || true + ''; }; }