puter/hosts/vessel/backup.nix

55 lines
1.4 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-02-04 20:51:11 +00:00
systemd.timers.local-backup = {
description = "Local rsync Backup";
wantedBy = ["timers.target"];
timerConfig = {
OnCalendar = "*-*-* 00:00:00";
Persistent = true;
Unit = "local-backup.service";
};
};
systemd.services.local-backup = {
description = "Local rsync Backup";
serviceConfig = {
Type = "oneshot";
2024-02-26 18:27:27 +00:00
ExecStart = "${lib.getExe pkgs.rsync} --verbose --verbose --archive --update --delete /srv/storage/ /srv/backup/";
2024-02-04 20:51:11 +00:00
User = "root";
Group = "root";
};
};
fileSystems."/srv/backup" = {
device = "/dev/disk/by-label/backup";
fsType = "btrfs";
options = ["subvol=main" "compress=zstd" "noatime"];
};
2024-02-26 18:27:27 +00:00
age.secrets."restic-${attrName}".file = ../../secrets/restic-lukas.age;
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"];
extraOptions = ["sftp.args='-i /etc/ssh/ssh_host_ed25519_key'"];
};
systemd.tmpfiles.settings = {
"10-storage-safe".${safePath}.d = {
user = "root";
group = "root";
mode = "0755";
};
};
2024-02-04 20:51:11 +00:00
}