Skip to content

Instantly share code, notes, and snippets.

@cole-h
Created February 25, 2021 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cole-h/234d4ce2236bd5affe40a55af2078229 to your computer and use it in GitHub Desktop.
Save cole-h/234d4ce2236bd5affe40a55af2078229 to your computer and use it in GitHub Desktop.
{
services.zrepl = {
enable = true;
settings = {
global = {
logging = [
{
type = "syslog";
level = "info";
format = "human";
}
];
};
jobs = [
{
name = "sys_user_snap";
type = "snap";
filesystems = {
"apool/ROOT/system<" = true;
"apool/ROOT/user<" = true;
};
snapshotting = {
type = "periodic";
interval = "5m";
prefix = "zrepl_snap_";
};
pruning.keep = [
{
# keep all non-zrepl snapshots
type = "regex";
negate = true;
regex = "^zrepl_.*";
}
{
type = "grid";
regex = "^zrepl_snap_.*";
grid = lib.concatStringsSep " | " [
"3x5m"
"16x15m"
"6x4h"
"7x1d"
"4x1w"
"52x1w"
];
}
];
}
{
name = "win10_snap";
type = "snap";
filesystems = {
"rpool/win10" = true;
};
snapshotting = {
type = "periodic";
interval = "4h";
prefix = "zrepl_win10_";
};
pruning.keep = [
{
# keep all non-zrepl snapshots
type = "regex";
negate = true;
regex = "^zrepl_.*";
}
{
type = "grid";
regex = "^zrepl_win10_.*";
grid = lib.concatStringsSep " | " [
"6x4h"
];
}
];
}
{
name = "push_to_bpool";
type = "push";
connect = {
type = "local";
listener_name = "bpool_sink";
client_identity = "${config.networking.hostName}";
};
filesystems = {
"apool/ROOT/system<" = true;
"apool/ROOT/user<" = true;
"apool/ROOT/user/home/vin/Downloads" = false;
"rpool/win10" = true;
};
send.encrypted = true;
# if space becomes an issue, uncomment below:
# replication.protection = {
# initial = "guarantee_resumability";
# # https://zrepl.github.io/configuration/replication.html#protection-option
# # sacrifice resumability in return for the ability to free disk space
# incremental = "guarantee_incremental";
# };
# snapshotting is handled by snap jobs
snapshotting.type = "manual";
pruning = {
# no-op prune rule on sender (keep all snapshots), snap jobs
# handle this
keep_sender = [
{
type = "regex";
regex = ".*";
}
];
keep_receiver = [
{
# keep all non-zrepl snapshots
type = "regex";
negate = true;
regex = "^zrepl_.*";
}
{
type = "grid";
regex = "^zrepl_snap_.*";
grid = lib.concatStringsSep " | " [
"1x1h(keep=all)"
"24x1h"
"365x1d"
];
}
{
type = "grid";
regex = "^zrepl_win10_.*";
grid = lib.concatStringsSep " | " [
"7x1d(keep=all)"
"4x1w"
];
}
];
};
}
{
name = "bpool_sink";
type = "sink";
root_fs = "bpool/zrepl/sink";
serve = {
type = "local";
listener_name = "bpool_sink";
};
# recv = {
# properties."inherit" = [
# "compression"
# ];
# };
}
];
};
};
systemd.services.zrepl-replicate = {
description = "Trigger zrepl replication for push_to_bpool";
serviceConfig.Type = "oneshot";
script = ''
${pkgs.zrepl}/bin/zrepl --config /etc/zrepl/zrepl.yml signal wakeup push_to_bpool
'';
};
systemd.timers.zrepl-replicate = {
description = "Trigger zrepl replication for push_to_bpool";
requires = [ "zfs-import.target" ];
wantedBy = [ "timers.target" "local-fs.target" ];
after = [ "zfs-import-bpool.service" ];
timerConfig = {
Unit = "zrepl-replicate.service";
OnCalendar = "daily";
Persistent = true;
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment