nix/modules/backups/default.nix
2026-08-28 02:20:28 +02:00

58 lines
1.4 KiB
Nix

{
config,
lib,
pkgs,
...
}:
{
programs.ssh.extraConfig = ''
Host nas01-backup
HostName 10.1.0.2
User _sa_backup
IdentityFile /etc/5335/id_backup_nas01
IdentitiesOnly yes
StrictHostKeyChecking accept-new
'';
services.restic.backups.system = {
initialize = true;
inhibitsSleep = true;
paths = [
"/etc"
"/srv"
"/boot"
"/home"
];
exclude = [
"/home/*/.cache"
"/home/*/.local/share/Steam"
"/home/*/.local/share/Trash"
"/home/*/.lmstudio"
"/home/*/Games"
"/home/*/Downloads"
"/home/*/Projects/**/target"
];
repository = "sftp:nas01-backup:/h_Backups/${config.networking.hostName}";
passwordFile = "/etc/5335/restic-password";
pruneOpts = [
"--keep-daily 7"
"--keep-weekly 5"
"--keep-monthly 6"
"--keep-yearly 10"
];
timerConfig = {
OnCalendar = "daily";
Persistent = true;
WakeSystem = true;
RandomizedDelaySec = "5h";
};
backupCleanupCommand = ''
loginctl list-sessions --no-legend | awk '{print $1}' | while read -r s; do
class=$(loginctl show-session "$s" -p Class --value)
if [ "$class" = "user" ]; then
loginctl show-session "$s" -p LockedHint --value
fi
done | grep -qx no && echo "unlocked session found skip suspend" || systemctl suspend
'';
};
}