fix borg lock

This commit is contained in:
Yan Lin 2025-10-22 10:00:16 +02:00
parent 8d74aeac0b
commit d30e2e3270

View file

@ -164,7 +164,7 @@ in
# Prevent concurrent backup runs # Prevent concurrent backup runs
unitConfig = { unitConfig = {
ConditionPathExists = "!/var/run/borg-backup.lock"; ConditionPathExists = "!/run/borg-backup.lock";
}; };
serviceConfig = { serviceConfig = {
@ -173,16 +173,16 @@ in
Group = "root"; Group = "root";
# Create lock file on start, remove on stop # Create lock file on start, remove on stop
ExecStartPre = "${pkgs.coreutils}/bin/touch /var/run/borg-backup.lock"; ExecStartPre = "${pkgs.coreutils}/bin/touch /run/borg-backup.lock";
ExecStopPost = "${pkgs.coreutils}/bin/rm -f /var/run/borg-backup.lock"; ExecStopPost = "${pkgs.coreutils}/bin/rm -f /run/borg-backup.lock";
# Security settings # Security settings
PrivateTmp = true; PrivateTmp = true;
ProtectSystem = "strict"; ProtectSystem = "strict";
# Disable ProtectHome for SSH repositories to allow SSH key access # Disable ProtectHome for SSH repositories to allow SSH key access
ProtectHome = mkIf (!(lib.hasPrefix "ssh://" cfg.repositoryUrl)) "read-only"; ProtectHome = mkIf (!(lib.hasPrefix "ssh://" cfg.repositoryUrl)) "read-only";
# Only add ReadWritePaths for local repositories # Add ReadWritePaths for lock file and local repositories
ReadWritePaths = mkIf (!(lib.hasPrefix "ssh://" cfg.repositoryUrl)) [ cfg.repositoryUrl ]; ReadWritePaths = [ "/run" ] ++ (if (lib.hasPrefix "ssh://" cfg.repositoryUrl) then [] else [ cfg.repositoryUrl ]);
# Environment # Environment
Environment = [ Environment = [
@ -375,6 +375,7 @@ in
borg-backup-now = "sudo systemctl start borg-backup.service"; borg-backup-now = "sudo systemctl start borg-backup.service";
borg-list = "BORG_REPO='${cfg.repositoryUrl}' BORG_RSH='${cfg.sshCommand}' borg list"; borg-list = "BORG_REPO='${cfg.repositoryUrl}' BORG_RSH='${cfg.sshCommand}' borg list";
borg-info = "BORG_REPO='${cfg.repositoryUrl}' BORG_RSH='${cfg.sshCommand}' borg info"; borg-info = "BORG_REPO='${cfg.repositoryUrl}' BORG_RSH='${cfg.sshCommand}' borg info";
borg-unlock = "sudo rm -f /run/borg-backup.lock && BORG_REPO='${cfg.repositoryUrl}' BORG_RSH='${cfg.sshCommand}' borg break-lock";
}; };
}; };
} }