2022-07-05 22:43:09 +00:00
|
|
|
# It's a setup for my backup.
|
2024-02-11 07:16:25 +00:00
|
|
|
{ config, lib, pkgs, foodogsquaredLib, ... }:
|
2022-02-19 08:58:08 +00:00
|
|
|
|
|
|
|
let
|
2023-12-15 06:14:15 +00:00
|
|
|
hostCfg = config.hosts.ni;
|
|
|
|
cfg = hostCfg.services.backup;
|
2022-02-19 08:58:08 +00:00
|
|
|
|
2023-01-11 05:16:02 +00:00
|
|
|
borgJobCommonSetting = { patterns ? [ ], passCommand }: {
|
2022-12-04 06:08:31 +00:00
|
|
|
compression = "zstd,12";
|
2022-02-19 08:58:08 +00:00
|
|
|
dateFormat = "+%F-%H-%M-%S-%z";
|
2022-12-04 06:08:31 +00:00
|
|
|
doInit = false;
|
2022-02-19 08:58:08 +00:00
|
|
|
encryption = {
|
2023-01-11 05:16:02 +00:00
|
|
|
inherit passCommand;
|
2022-02-19 08:58:08 +00:00
|
|
|
mode = "repokey-blake2";
|
|
|
|
};
|
|
|
|
extraCreateArgs = lib.concatStringsSep " "
|
|
|
|
(builtins.map (patternFile: "--patterns-from ${patternFile}") patterns);
|
|
|
|
extraInitArgs = "--make-parent-dirs";
|
|
|
|
|
|
|
|
# We're emptying them since we're specifying them all through the patterns file.
|
|
|
|
paths = [ ];
|
|
|
|
|
|
|
|
persistentTimer = true;
|
|
|
|
preHook = ''
|
|
|
|
extraCreateArgs="$extraCreateArgs --exclude-if-present .nobackup"
|
|
|
|
extraCreateArgs="$extraCreateArgs --stats"
|
|
|
|
'';
|
|
|
|
prune = {
|
|
|
|
keep = {
|
|
|
|
within = "1d";
|
|
|
|
hourly = 8;
|
|
|
|
daily = 30;
|
|
|
|
weekly = 4;
|
|
|
|
monthly = 6;
|
|
|
|
yearly = 3;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-07 02:51:49 +00:00
|
|
|
hetzner-boxes-user = "u332477";
|
|
|
|
hetzner-boxes-server = "${hetzner-boxes-user}.your-storagebox.de";
|
2023-07-05 05:14:38 +00:00
|
|
|
|
|
|
|
pathPrefix = "borg-backup";
|
2022-09-01 14:47:22 +00:00
|
|
|
in
|
|
|
|
{
|
2023-12-15 06:14:15 +00:00
|
|
|
options.hosts.ni.services.backup.enable =
|
2022-02-19 08:58:08 +00:00
|
|
|
lib.mkEnableOption "backup setup with BorgBackup";
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2024-02-11 07:16:25 +00:00
|
|
|
sops.secrets = foodogsquaredLib.sops-nix.getSecrets
|
2023-12-15 06:14:15 +00:00
|
|
|
./secrets.yaml
|
2024-02-11 07:16:25 +00:00
|
|
|
(foodogsquaredLib.sops-nix.attachSopsPathPrefix pathPrefix {
|
2023-07-05 05:04:52 +00:00
|
|
|
"patterns/home" = { };
|
|
|
|
"patterns/etc" = { };
|
|
|
|
"patterns/keys" = { };
|
|
|
|
"patterns/remote-backup" = { };
|
|
|
|
"repos/archive/password" = { };
|
|
|
|
"repos/external-drive/password" = { };
|
|
|
|
"repos/hetzner-box/password" = { };
|
|
|
|
"ssh-key" = { };
|
|
|
|
});
|
2022-02-19 08:58:08 +00:00
|
|
|
|
2024-01-22 06:48:55 +00:00
|
|
|
suites.filesystem.setups = {
|
2022-08-20 05:07:13 +00:00
|
|
|
archive.enable = true;
|
|
|
|
external-hdd.enable = true;
|
2022-07-09 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
2022-02-19 08:58:08 +00:00
|
|
|
services.borgbackup.jobs = {
|
2022-09-01 14:47:22 +00:00
|
|
|
local-archive = borgJobCommonSetting
|
|
|
|
{
|
|
|
|
patterns = with config.sops; [
|
2023-07-05 05:14:38 +00:00
|
|
|
secrets."${pathPrefix}/patterns/home".path
|
|
|
|
secrets."${pathPrefix}/patterns/etc".path
|
|
|
|
secrets."${pathPrefix}/patterns/keys".path
|
2022-09-01 14:47:22 +00:00
|
|
|
];
|
2023-07-05 05:14:38 +00:00
|
|
|
passCommand = "cat ${config.sops.secrets."${pathPrefix}/repos/archive/password".path}";
|
2022-09-01 14:47:22 +00:00
|
|
|
} // {
|
2022-07-09 21:43:32 +00:00
|
|
|
removableDevice = true;
|
|
|
|
repo = "/mnt/archives/backups";
|
2023-09-19 05:01:55 +00:00
|
|
|
startAt = "04:30";
|
2022-02-19 08:58:08 +00:00
|
|
|
};
|
|
|
|
|
2022-09-01 14:47:22 +00:00
|
|
|
local-external-drive = borgJobCommonSetting
|
|
|
|
{
|
|
|
|
patterns = with config.sops; [
|
2023-07-05 05:14:38 +00:00
|
|
|
secrets."${pathPrefix}/patterns/home".path
|
|
|
|
secrets."${pathPrefix}/patterns/etc".path
|
|
|
|
secrets."${pathPrefix}/patterns/keys".path
|
2022-09-01 14:47:22 +00:00
|
|
|
];
|
2023-07-05 05:14:38 +00:00
|
|
|
passCommand = "cat ${config.sops.secrets."${pathPrefix}/repos/external-drive/password".path}";
|
2022-09-01 14:47:22 +00:00
|
|
|
} // {
|
2022-02-19 08:58:08 +00:00
|
|
|
removableDevice = true;
|
|
|
|
repo = "/mnt/external-storage/backups";
|
2023-09-19 05:01:55 +00:00
|
|
|
startAt = "04:30";
|
2022-02-19 08:58:08 +00:00
|
|
|
};
|
|
|
|
|
2024-02-11 07:16:25 +00:00
|
|
|
#remote-backup-hetzner-box = borgJobCommonSetting
|
|
|
|
# {
|
|
|
|
# patterns = with config.sops; [
|
|
|
|
# secrets."${pathPrefix}/patterns/remote-backup".path
|
|
|
|
# ];
|
|
|
|
# passCommand = "cat ${config.sops.secrets."${pathPrefix}/repos/hetzner-box/password".path}";
|
|
|
|
# } // {
|
|
|
|
# doInit = true;
|
|
|
|
# repo = "ssh://${hetzner-boxes-user}@${hetzner-boxes-server}:23/./borg/desktop/ni";
|
|
|
|
# startAt = "04:30";
|
|
|
|
# environment.BORG_RSH = "ssh -i ${config.sops.secrets."${pathPrefix}/ssh-key".path}";
|
|
|
|
#};
|
2022-02-19 08:58:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
programs.ssh.extraConfig = ''
|
2023-01-07 02:51:49 +00:00
|
|
|
Host ${hetzner-boxes-server}
|
2023-07-05 05:14:38 +00:00
|
|
|
IdentityFile ${config.sops.secrets."${pathPrefix}/ssh-key".path}
|
2022-02-19 08:58:08 +00:00
|
|
|
'';
|
2024-01-25 04:19:29 +00:00
|
|
|
|
|
|
|
services.btrfs.autoScrub = {
|
|
|
|
enable = true;
|
|
|
|
fileSystems = [
|
|
|
|
"/mnt/archives"
|
|
|
|
];
|
|
|
|
};
|
2022-02-19 08:58:08 +00:00
|
|
|
};
|
|
|
|
}
|