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

@ -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;