zfsborg: restructure config
Preparing for 2 repo destinations.
This commit is contained in:
parent
866347b042
commit
583f74cf3f
|
@ -49,8 +49,9 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
passwordPath = config.age.secrets.borgbackup-password.path;
|
passwordPath = config.age.secrets.borgbackup-password.path;
|
||||||
sshKeyPath = "/etc/ssh/ssh_host_ed25519_key";
|
sshKeyPath = "/etc/ssh/ssh_host_ed25519_key";
|
||||||
mountpoints = {
|
dirs = [
|
||||||
"/var/lib" = {
|
{
|
||||||
|
mountpoint = "/var/lib";
|
||||||
repo = "zh2769@zh2769.rsync.net:${config.networking.hostName}.${config.networking.domain}-var_lib";
|
repo = "zh2769@zh2769.rsync.net:${config.networking.hostName}.${config.networking.domain}-var_lib";
|
||||||
paths = [
|
paths = [
|
||||||
"/var/lib/.snapshot-latest/bitwarden_rs"
|
"/var/lib/.snapshot-latest/bitwarden_rs"
|
||||||
|
@ -64,8 +65,9 @@
|
||||||
"/var/lib/.snapshot-latest/private/soju"
|
"/var/lib/.snapshot-latest/private/soju"
|
||||||
];
|
];
|
||||||
backup_at = "*-*-* 00:01:00";
|
backup_at = "*-*-* 00:01:00";
|
||||||
};
|
}
|
||||||
"/var/log" = {
|
{
|
||||||
|
mountpoint = "/var/log";
|
||||||
repo = "zh2769@zh2769.rsync.net:${config.networking.hostName}.${config.networking.domain}-var_log";
|
repo = "zh2769@zh2769.rsync.net:${config.networking.hostName}.${config.networking.domain}-var_log";
|
||||||
paths = ["/var/log/.snapshot-latest/caddy/"];
|
paths = ["/var/log/.snapshot-latest/caddy/"];
|
||||||
patterns = [
|
patterns = [
|
||||||
|
@ -73,16 +75,17 @@
|
||||||
"- *"
|
"- *"
|
||||||
];
|
];
|
||||||
backup_at = "*-*-* 00:01:00";
|
backup_at = "*-*-* 00:01:00";
|
||||||
};
|
}
|
||||||
"/home" = {
|
{
|
||||||
|
mountpoint = "/home";
|
||||||
repo = "zh2769@zh2769.rsync.net:${config.networking.hostName}.${config.networking.domain}-home-motiejus-annex2";
|
repo = "zh2769@zh2769.rsync.net:${config.networking.hostName}.${config.networking.domain}-home-motiejus-annex2";
|
||||||
paths = [
|
paths = [
|
||||||
"/home/.snapshot-latest/motiejus/annex2"
|
"/home/.snapshot-latest/motiejus/annex2"
|
||||||
"/home/.snapshot-latest/motiejus/.config/syncthing"
|
"/home/.snapshot-latest/motiejus/.config/syncthing"
|
||||||
];
|
];
|
||||||
backup_at = "*-*-* 00:05:00 UTC";
|
backup_at = "*-*-* 00:05:00 UTC";
|
||||||
};
|
}
|
||||||
};
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
unitstatus = {
|
unitstatus = {
|
||||||
|
|
|
@ -24,11 +24,12 @@ in {
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
mountpoints = lib.mkOption {
|
dirs = lib.mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = attrsOf (submodule (
|
type = listOf (submodule (
|
||||||
{...}: {
|
{...}: {
|
||||||
options = {
|
options = {
|
||||||
|
mountpoint = lib.mkOption {type = path;};
|
||||||
repo = lib.mkOption {type = str;};
|
repo = lib.mkOption {type = str;};
|
||||||
paths = lib.mkOption {type = listOf path;};
|
paths = lib.mkOption {type = listOf path;};
|
||||||
patterns = lib.mkOption {
|
patterns = lib.mkOption {
|
||||||
|
@ -42,9 +43,10 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf config.mj.base.zfsborg.enable {
|
config = with config.mj.base.zfsborg;
|
||||||
|
lib.mkIf enable {
|
||||||
systemd.services."zfsborg-snapshot-dirs" = let
|
systemd.services."zfsborg-snapshot-dirs" = let
|
||||||
mountpoints = lib.unique (lib.attrNames config.mj.base.zfsborg.mountpoints);
|
mountpoints = lib.unique (lib.catAttrs "mountpoint" dirs);
|
||||||
in {
|
in {
|
||||||
description = "zfsborg prepare snapshot directories";
|
description = "zfsborg prepare snapshot directories";
|
||||||
wantedBy = ["multi-user.target"];
|
wantedBy = ["multi-user.target"];
|
||||||
|
@ -58,7 +60,9 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.borgbackup.jobs = lib.mapAttrs' (mountpoint: attrs: let
|
services.borgbackup.jobs = builtins.listToAttrs (
|
||||||
|
map (attrs: let
|
||||||
|
mountpoint = builtins.getAttr "mountpoint" attrs;
|
||||||
fs = builtins.getAttr mountpoint config.fileSystems;
|
fs = builtins.getAttr mountpoint config.fileSystems;
|
||||||
in
|
in
|
||||||
assert fs.fsType == "zfs";
|
assert fs.fsType == "zfs";
|
||||||
|
@ -91,15 +95,15 @@ in {
|
||||||
// lib.optionalAttrs (attrs ? patterns) {
|
// lib.optionalAttrs (attrs ? patterns) {
|
||||||
patterns = attrs.patterns;
|
patterns = attrs.patterns;
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs (config.mj.base.zfsborg.sshKeyPath != null) {
|
// lib.optionalAttrs (sshKeyPath != null) {
|
||||||
environment.BORG_RSH = ''ssh -i "${config.mj.base.zfsborg.sshKeyPath}"'';
|
environment.BORG_RSH = ''ssh -i "${config.mj.base.zfsborg.sshKeyPath}"'';
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
config.mj.base.zfsborg.mountpoints;
|
dirs
|
||||||
|
);
|
||||||
|
|
||||||
mj.base.unitstatus.units = let
|
mj.base.unitstatus.units = let
|
||||||
mounts = config.mj.base.zfsborg.mountpoints;
|
sanitized = map lib.strings.sanitizeDerivationName (lib.catAttrs "mountpoint" dirs);
|
||||||
sanitized = map lib.strings.sanitizeDerivationName (lib.attrNames mounts);
|
|
||||||
in
|
in
|
||||||
map (n: "borgbackup-job-${n}") sanitized;
|
map (n: "borgbackup-job-${n}") sanitized;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue