puter/hosts/vessel/backup.nix

61 lines
1.6 KiB
Nix
Raw Normal View History

2024-02-04 20:51:11 +00:00
{
2024-02-26 18:27:27 +00:00
attrName,
config,
2024-02-04 20:51:11 +00:00
lib,
2024-02-26 18:27:27 +00:00
pkgs,
2024-02-04 20:51:11 +00:00
...
2024-02-26 18:27:27 +00:00
}: let
safePath = "/srv/storage/safe";
in {
2024-03-08 21:46:46 +00:00
systemd = {
timers.local-backup = {
description = "Local rsync Backup";
wantedBy = ["timers.target"];
timerConfig = {
OnCalendar = "*-*-* 03:00:00";
Persistent = true;
Unit = "local-backup.service";
};
};
services.local-backup = {
description = "Local rsync Backup";
serviceConfig = {
Type = "oneshot";
ExecStart = "${lib.getExe pkgs.rsync} --verbose --verbose --archive --update --delete /srv/storage/ /srv/backup/";
User = "root";
Group = "root";
};
2024-02-04 20:51:11 +00:00
};
2024-03-08 21:46:46 +00:00
tmpfiles.settings = {
"10-storage-safe".${safePath}.d = {
user = "root";
group = "root";
mode = "0755";
};
2024-02-04 20:51:11 +00:00
};
};
fileSystems."/srv/backup" = {
device = "/dev/disk/by-label/backup";
fsType = "btrfs";
2024-04-21 17:00:39 +00:00
options = ["subvol=/" "compress=zstd" "noatime"];
2024-02-04 20:51:11 +00:00
};
2024-02-26 18:27:27 +00:00
2024-02-27 20:38:42 +00:00
age.secrets."restic-${attrName}".file = ../../secrets/restic-${attrName}.age;
2024-02-26 18:27:27 +00:00
services.restic.backups.${attrName} = {
2024-02-27 20:37:58 +00:00
repository = "sftp:u385962@u385962.your-storagebox.de:/restic/${attrName}";
2024-02-26 18:27:27 +00:00
initialize = true;
paths = [safePath];
passwordFile = config.age.secrets."restic-${attrName}".path;
pruneOpts = ["--keep-daily 7" "--keep-weekly 5" "--keep-monthly 12"];
2024-03-08 21:46:46 +00:00
timerConfig = {
OnCalendar = "*-*-* 03:00:00";
Persistent = true;
2024-02-26 18:27:27 +00:00
};
2024-03-08 21:46:46 +00:00
extraOptions = ["sftp.args='-i /etc/ssh/ssh_host_ed25519_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"];
2024-02-26 18:27:27 +00:00
};
2024-02-04 20:51:11 +00:00
}