add borg lock mechanism

This commit is contained in:
Yan Lin 2025-10-22 09:54:03 +02:00
parent 5936f7d0a7
commit 8d74aeac0b

View file

@ -162,11 +162,20 @@ in
# Add borg and required tools to the service's PATH # Add borg and required tools to the service's PATH
path = [ pkgs.borgbackup pkgs.openssh pkgs.curl ]; path = [ pkgs.borgbackup pkgs.openssh pkgs.curl ];
# Prevent concurrent backup runs
unitConfig = {
ConditionPathExists = "!/var/run/borg-backup.lock";
};
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
User = "root"; # Need root to access all backup paths User = "root"; # Need root to access all backup paths
Group = "root"; 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 # Security settings
PrivateTmp = true; PrivateTmp = true;
ProtectSystem = "strict"; ProtectSystem = "strict";