From 8d74aeac0bb9772546c4c45938f70250acffe6d0 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Wed, 22 Oct 2025 09:54:03 +0200 Subject: [PATCH] add borg lock mechanism --- modules/borg-client.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/borg-client.nix b/modules/borg-client.nix index c1a5dae..9c64cf9 100644 --- a/modules/borg-client.nix +++ b/modules/borg-client.nix @@ -158,14 +158,23 @@ in description = "Borg Backup Service"; wants = [ "network-online.target" ]; after = [ "network-online.target" ]; - + # Add borg and required tools to the service's PATH path = [ pkgs.borgbackup pkgs.openssh pkgs.curl ]; + # Prevent concurrent backup runs + unitConfig = { + ConditionPathExists = "!/var/run/borg-backup.lock"; + }; + serviceConfig = { Type = "oneshot"; User = "root"; # Need root to access all backup paths Group = "root"; + + # Create lock file on start, remove on stop + ExecStartPre = "${pkgs.coreutils}/bin/touch /var/run/borg-backup.lock"; + ExecStopPost = "${pkgs.coreutils}/bin/rm -f /var/run/borg-backup.lock"; # Security settings PrivateTmp = true;