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:
parent
9d2c43eb6c
commit
6d02ed0e0e
1 changed files with 71 additions and 66 deletions
|
@ -3,16 +3,18 @@
|
||||||
let
|
let
|
||||||
secrets = import ./lib/secrets.nix;
|
secrets = import ./lib/secrets.nix;
|
||||||
|
|
||||||
# Make a local zrepl push job from primary to the target zpool.
|
# Create a local zrepl push job from source to the target zpool.
|
||||||
pushLocal = (zpool: {
|
pushLocal = (source:
|
||||||
name = pushName zpool;
|
(target: {
|
||||||
|
name = pushName source target;
|
||||||
type = "push";
|
type = "push";
|
||||||
|
|
||||||
# Replicate all of primary locally.
|
# Replicate all of the source zpool locally.
|
||||||
filesystems."primary<" = true;
|
filesystems."${source}<" = true;
|
||||||
connect = {
|
connect = {
|
||||||
type = "local";
|
type = "local";
|
||||||
listener_name = sinkName zpool;
|
listener_name = sinkName target;
|
||||||
|
# Assumes only a single client will ever push locally to sink.
|
||||||
client_identity = "local";
|
client_identity = "local";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,14 +42,19 @@ let
|
||||||
# Keep the same automatic snapshots as source.
|
# Keep the same automatic snapshots as source.
|
||||||
keep_receiver = [ keepGrid ];
|
keep_receiver = [ keepGrid ];
|
||||||
};
|
};
|
||||||
});
|
}));
|
||||||
|
|
||||||
# Make a local zrepl sink job to the target zpool.
|
# Make a local zrepl sink job to the target zpool.
|
||||||
sinkLocal = (zpool: {
|
sinkLocal = (zpool: {
|
||||||
name = sinkName zpool;
|
name = sinkName zpool;
|
||||||
type = "sink";
|
type = "sink";
|
||||||
root_fs = "${zpool}";
|
root_fs = "${zpool}";
|
||||||
recv.properties = {
|
|
||||||
|
recv = {
|
||||||
|
# Necessary for encrypted destination with unencrypted source.
|
||||||
|
placeholder.encryption = "inherit";
|
||||||
|
|
||||||
|
properties = {
|
||||||
# Inherit any encryption properties.
|
# Inherit any encryption properties.
|
||||||
"inherit" = [ "encryption" "keyformat" "keylocation" ];
|
"inherit" = [ "encryption" "keyformat" "keylocation" ];
|
||||||
|
|
||||||
|
@ -67,23 +74,20 @@ let
|
||||||
"com.sun:auto-snapshot:monthly" = false;
|
"com.sun:auto-snapshot:monthly" = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
serve = {
|
serve = {
|
||||||
type = "local";
|
type = "local";
|
||||||
listener_name = "sink_${zpool}";
|
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?
|
# TODO(mdlayher): it would be nice to prefix this with push_ but job renames
|
||||||
sinkLocalEncrypted = (zpool:
|
# are not possible without major upheaval. See:
|
||||||
lib.mkMerge [
|
# https://github.com/zrepl/zrepl/issues/327.
|
||||||
(sinkLocal zpool)
|
pushName = (source: (target: "${source}_to_${target}"));
|
||||||
{ recv.placeholder.encryption = "inherit"; }
|
|
||||||
]);
|
|
||||||
|
|
||||||
# Generate the zrepl push job name for a target zpool.
|
|
||||||
pushName = (zpool: "primary_to_${zpool}");
|
|
||||||
|
|
||||||
# Generate the zrepl sink job name for a target zpool.
|
# Generate the zrepl sink job name for a target zpool.
|
||||||
sinkName = (zpool: "sink_${zpool}");
|
sinkName = (zpool: "sink_${zpool}");
|
||||||
|
@ -207,15 +211,16 @@ in {
|
||||||
listen = ":9811";
|
listen = ":9811";
|
||||||
}];
|
}];
|
||||||
jobs = [
|
jobs = [
|
||||||
# Replicate from primary pool to sinks.
|
# Replicate from primary to secondary.
|
||||||
(pushLocal "secondary")
|
#
|
||||||
(pushLocal "backup0")
|
# TODO(mdlayher): fan-out replication from secondary to backup{0,1},
|
||||||
(pushLocal "backup1")
|
# 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.
|
# Local sink jobs for backups.
|
||||||
(sinkLocal "secondary")
|
(sinkLocal "secondary")
|
||||||
(sinkLocalEncrypted "backup0")
|
|
||||||
(sinkLocalEncrypted "backup1")
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue