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,87 +3,91 @@
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: {
type = "push"; name = pushName source target;
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;
client_identity = "local"; # Assumes only a single client will ever push locally to sink.
}; client_identity = "local";
};
# Snapshot every 15 minutes. # Snapshot every 15 minutes.
snapshotting = { snapshotting = {
type = "periodic"; type = "periodic";
prefix = "zrepl_"; prefix = "zrepl_";
interval = "15m"; interval = "15m";
}; };
pruning = { pruning = {
keep_sender = [ keep_sender = [
# Keep snapshots that are not already replicated. # Keep snapshots that are not already replicated.
{ {
type = "not_replicated"; type = "not_replicated";
} }
# Keep manual snapshots. # Keep manual snapshots.
{ {
type = "regex"; type = "regex";
regex = "^manual_.*"; regex = "^manual_.*";
} }
# Keep time-based bucketed snapshots. # Keep time-based bucketed snapshots.
keepGrid keepGrid
]; ];
# 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 = {
# Inherit any encryption properties.
"inherit" = [ "encryption" "keyformat" "keylocation" ];
override = { recv = {
# Always enable compression. # Necessary for encrypted destination with unencrypted source.
compression = "on"; placeholder.encryption = "inherit";
# Do not mount sink pools. properties = {
mountpoint = "none"; # Inherit any encryption properties.
"inherit" = [ "encryption" "keyformat" "keylocation" ];
# Do not auto-snapshot sink pools. override = {
"com.sun:auto-snapshot" = false; # Always enable compression.
"com.sun:auto-snapshot:frequent" = false; compression = "on";
"com.sun:auto-snapshot:hourly" = false;
"com.sun:auto-snapshot:daily" = false; # Do not mount sink pools.
"com.sun:auto-snapshot:weekly" = false; mountpoint = "none";
"com.sun:auto-snapshot:monthly" = false;
# Do not auto-snapshot sink pools.
"com.sun:auto-snapshot" = false;
"com.sun:auto-snapshot:frequent" = false;
"com.sun:auto-snapshot:hourly" = false;
"com.sun:auto-snapshot:daily" = false;
"com.sun:auto-snapshot:weekly" = 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")
]; ];
}; };
}; };