1
0
Fork 0
mirror of https://github.com/mdlayher/homelab.git synced 2024-12-14 11:47:32 +00:00

nixos/servnerr-3: zrepl snapshot/replication from primary to secondary only for now

Signed-off-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
Matt Layher 2022-02-14 16:58:00 -05:00
parent 9d2c43eb6c
commit 6d02ed0e0e
No known key found for this signature in database
GPG key ID: 77BFE531397EDE94

View file

@ -3,16 +3,18 @@
let
secrets = import ./lib/secrets.nix;
# Make a local zrepl push job from primary to the target zpool.
pushLocal = (zpool: {
name = pushName zpool;
# Create a local zrepl push job from source to the target zpool.
pushLocal = (source:
(target: {
name = pushName source target;
type = "push";
# Replicate all of primary locally.
filesystems."primary<" = true;
# Replicate all of the source zpool locally.
filesystems."${source}<" = true;
connect = {
type = "local";
listener_name = sinkName zpool;
listener_name = sinkName target;
# Assumes only a single client will ever push locally to sink.
client_identity = "local";
};
@ -40,14 +42,19 @@ let
# Keep the same automatic snapshots as source.
keep_receiver = [ keepGrid ];
};
});
}));
# Make a local zrepl sink job to the target zpool.
sinkLocal = (zpool: {
name = sinkName zpool;
type = "sink";
root_fs = "${zpool}";
recv.properties = {
recv = {
# Necessary for encrypted destination with unencrypted source.
placeholder.encryption = "inherit";
properties = {
# Inherit any encryption properties.
"inherit" = [ "encryption" "keyformat" "keylocation" ];
@ -67,23 +74,20 @@ let
"com.sun:auto-snapshot:monthly" = false;
};
};
};
serve = {
type = "local";
listener_name = "sink_${zpool}";
};
});
# Make a local zrepl encrypted sink job to the target zpool.
# Generate the zrepl push job name for a source and target zpool.
#
# TODO(mdlayher): unconditionally set this in sinkLocal anyway?
sinkLocalEncrypted = (zpool:
lib.mkMerge [
(sinkLocal zpool)
{ recv.placeholder.encryption = "inherit"; }
]);
# Generate the zrepl push job name for a target zpool.
pushName = (zpool: "primary_to_${zpool}");
# TODO(mdlayher): it would be nice to prefix this with push_ but job renames
# are not possible without major upheaval. See:
# https://github.com/zrepl/zrepl/issues/327.
pushName = (source: (target: "${source}_to_${target}"));
# Generate the zrepl sink job name for a target zpool.
sinkName = (zpool: "sink_${zpool}");
@ -207,15 +211,16 @@ in {
listen = ":9811";
}];
jobs = [
# Replicate from primary pool to sinks.
(pushLocal "secondary")
(pushLocal "backup0")
(pushLocal "backup1")
# Replicate from primary to secondary.
#
# TODO(mdlayher): fan-out replication from secondary to backup{0,1},
# and make smart logic like a udev listener to signal replication when
# the drives are plugged in and spun up.
# https://zrepl.github.io/quickstart/fan_out_replication.html
(pushLocal "primary" "secondary")
# Local sink jobs for backups.
(sinkLocal "secondary")
(sinkLocalEncrypted "backup0")
(sinkLocalEncrypted "backup1")
];
};
};