2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
with types;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
planDescription = ''
|
|
|
|
The znapzend backup plan to use for the source.
|
|
|
|
|
|
|
|
The plan specifies how often to backup and for how long to keep the
|
2022-12-28 21:21:41 +00:00
|
|
|
backups. It consists of a series of retention periods to interval
|
2020-04-24 23:36:52 +00:00
|
|
|
associations:
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
retA=>intA,retB=>intB,...
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
Both intervals and retention periods are expressed in standard units
|
|
|
|
of time or multiples of them. You can use both the full name or a
|
|
|
|
shortcut according to the following listing:
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
second|sec|s, minute|min, hour|h, day|d, week|w, month|mon|m, year|y
|
2022-09-09 14:08:57 +00:00
|
|
|
```
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
See {manpage}`znapzendzetup(1)` for more info.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
planExample = "1h=>10min,1d=>1h,1w=>1d,1m=>1w,1y=>1m";
|
|
|
|
|
|
|
|
# A type for a string of the form number{b|k|M|G}
|
|
|
|
mbufferSizeType = str // {
|
|
|
|
check = x: str.check x && builtins.isList (builtins.match "^[0-9]+[bkMG]$" x);
|
|
|
|
description = "string of the form number{b|k|M|G}";
|
|
|
|
};
|
|
|
|
|
|
|
|
enabledFeatures = concatLists (mapAttrsToList (name: enabled: optional enabled name) cfg.features);
|
|
|
|
|
|
|
|
# Type for a string that must contain certain other strings (the list parameter).
|
|
|
|
# Note that these would need regex escaping.
|
|
|
|
stringContainingStrings = list: let
|
|
|
|
matching = s: map (str: builtins.match ".*${str}.*" s) list;
|
|
|
|
in str // {
|
|
|
|
check = x: str.check x && all isList (matching x);
|
|
|
|
description = "string containing all of the characters ${concatStringsSep ", " list}";
|
|
|
|
};
|
|
|
|
|
|
|
|
timestampType = stringContainingStrings [ "%Y" "%m" "%d" "%H" "%M" "%S" ];
|
|
|
|
|
|
|
|
destType = srcConfig: submodule ({ name, ... }: {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
label = mkOption {
|
|
|
|
type = str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Label for this destination. Defaults to the attribute name.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
plan = mkOption {
|
|
|
|
type = str;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc planDescription;
|
2020-04-24 23:36:52 +00:00
|
|
|
example = planExample;
|
|
|
|
};
|
|
|
|
|
|
|
|
dataset = mkOption {
|
|
|
|
type = str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Dataset name to send snapshots to.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "tank/main";
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = nullOr str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Host to use for the destination dataset. Can be prefixed with
|
2022-08-12 12:06:08 +00:00
|
|
|
`user@` to specify the ssh user.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
example = "john@example.com";
|
|
|
|
};
|
|
|
|
|
|
|
|
presend = mkOption {
|
|
|
|
type = nullOr str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Command to run before sending the snapshot to the destination.
|
2022-08-12 12:06:08 +00:00
|
|
|
Intended to run a remote script via {command}`ssh` on the
|
2020-04-24 23:36:52 +00:00
|
|
|
destination, e.g. to bring up a backup disk or server or to put a
|
2022-08-12 12:06:08 +00:00
|
|
|
zpool online/offline. See also {option}`postsend`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
example = "ssh root@bserv zpool import -Nf tank";
|
|
|
|
};
|
|
|
|
|
|
|
|
postsend = mkOption {
|
|
|
|
type = nullOr str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Command to run after sending the snapshot to the destination.
|
2022-08-12 12:06:08 +00:00
|
|
|
Intended to run a remote script via {command}`ssh` on the
|
2020-04-24 23:36:52 +00:00
|
|
|
destination, e.g. to bring up a backup disk or server or to put a
|
2022-08-12 12:06:08 +00:00
|
|
|
zpool online/offline. See also {option}`presend`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
example = "ssh root@bserv zpool export tank";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
label = mkDefault name;
|
|
|
|
plan = mkDefault srcConfig.plan;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srcType = submodule ({ name, config, ... }: {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to enable this source.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
recursive = mkOption {
|
|
|
|
type = bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to do recursive snapshots.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
mbuffer = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to use {command}`mbuffer`.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = nullOr ints.u16;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Port to use for {command}`mbuffer`.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If this is null, it will run {command}`mbuffer` through
|
2020-04-24 23:36:52 +00:00
|
|
|
ssh.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If this is not null, it will run {command}`mbuffer`
|
2020-04-24 23:36:52 +00:00
|
|
|
directly through TCP, which is not encrypted but faster. In that
|
|
|
|
case the given port needs to be open on the destination host.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
size = mkOption {
|
|
|
|
type = mbufferSizeType;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The size for {command}`mbuffer`.
|
2020-04-24 23:36:52 +00:00
|
|
|
Supports the units b, k, M, G.
|
|
|
|
'';
|
|
|
|
default = "1G";
|
|
|
|
example = "128M";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
presnap = mkOption {
|
|
|
|
type = nullOr str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Command to run before snapshots are taken on the source dataset,
|
|
|
|
e.g. for database locking/flushing. See also
|
2022-08-12 12:06:08 +00:00
|
|
|
{option}`postsnap`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
default = null;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
|
|
|
'''''${pkgs.mariadb}/bin/mysql -e "set autocommit=0;flush tables with read lock;\\! ''${pkgs.coreutils}/bin/sleep 600" & ''${pkgs.coreutils}/bin/echo $! > /tmp/mariadblock.pid ; sleep 10'''
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
postsnap = mkOption {
|
|
|
|
type = nullOr str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Command to run after snapshots are taken on the source dataset,
|
2022-08-12 12:06:08 +00:00
|
|
|
e.g. for database unlocking. See also {option}`presnap`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
default = null;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
|
|
|
"''${pkgs.coreutils}/bin/kill `''${pkgs.coreutils}/bin/cat /tmp/mariadblock.pid`;''${pkgs.coreutils}/bin/rm /tmp/mariadblock.pid"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
timestampFormat = mkOption {
|
|
|
|
type = timestampType;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The timestamp format to use for constructing snapshot names.
|
2022-08-12 12:06:08 +00:00
|
|
|
The syntax is `strftime`-like. The string must
|
|
|
|
consist of the mandatory `%Y %m %d %H %M %S`.
|
|
|
|
Optionally `- _ . :` characters as well as any
|
2020-04-24 23:36:52 +00:00
|
|
|
alphanumeric character are allowed. If suffixed by a
|
2022-08-12 12:06:08 +00:00
|
|
|
`Z`, times will be in UTC.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
default = "%Y-%m-%d-%H%M%S";
|
|
|
|
example = "znapzend-%m.%d.%Y-%H%M%SZ";
|
|
|
|
};
|
|
|
|
|
|
|
|
sendDelay = mkOption {
|
|
|
|
type = int;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Specify delay (in seconds) before sending snaps to the destination.
|
|
|
|
May be useful if you want to control sending time.
|
|
|
|
'';
|
|
|
|
default = 0;
|
|
|
|
example = 60;
|
|
|
|
};
|
|
|
|
|
|
|
|
plan = mkOption {
|
|
|
|
type = str;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc planDescription;
|
2020-04-24 23:36:52 +00:00
|
|
|
example = planExample;
|
|
|
|
};
|
|
|
|
|
|
|
|
dataset = mkOption {
|
|
|
|
type = str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The dataset to use for this source.";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "tank/home";
|
|
|
|
};
|
|
|
|
|
|
|
|
destinations = mkOption {
|
2020-09-25 04:45:31 +00:00
|
|
|
type = attrsOf (destType config);
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Additional destinations.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = {};
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
local = {
|
|
|
|
dataset = "btank/backup";
|
|
|
|
presend = "zpool import -N btank";
|
|
|
|
postsend = "zpool export btank";
|
|
|
|
};
|
|
|
|
remote = {
|
|
|
|
host = "john@example.com";
|
|
|
|
dataset = "tank/john";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
dataset = mkDefault name;
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
### Generating the configuration from here
|
|
|
|
|
|
|
|
cfg = config.services.znapzend;
|
|
|
|
|
|
|
|
onOff = b: if b then "on" else "off";
|
|
|
|
nullOff = b: if b == null then "off" else toString b;
|
|
|
|
stripSlashes = replaceStrings [ "/" ] [ "." ];
|
|
|
|
|
|
|
|
attrsToFile = config: concatStringsSep "\n" (builtins.attrValues (
|
|
|
|
mapAttrs (n: v: "${n}=${v}") config));
|
|
|
|
|
|
|
|
mkDestAttrs = dst: with dst;
|
|
|
|
mapAttrs' (n: v: nameValuePair "dst_${label}${n}" v) ({
|
|
|
|
"" = optionalString (host != null) "${host}:" + dataset;
|
|
|
|
_plan = plan;
|
|
|
|
} // optionalAttrs (presend != null) {
|
|
|
|
_precmd = presend;
|
|
|
|
} // optionalAttrs (postsend != null) {
|
|
|
|
_pstcmd = postsend;
|
|
|
|
});
|
|
|
|
|
|
|
|
mkSrcAttrs = srcCfg: with srcCfg; {
|
|
|
|
enabled = onOff enable;
|
2022-12-28 21:21:41 +00:00
|
|
|
# mbuffer is not referenced by its full path to accommodate non-NixOS systems or differing mbuffer versions between source and target
|
2020-05-15 21:57:56 +00:00
|
|
|
mbuffer = with mbuffer; if enable then "mbuffer"
|
2020-04-24 23:36:52 +00:00
|
|
|
+ optionalString (port != null) ":${toString port}" else "off";
|
|
|
|
mbuffer_size = mbuffer.size;
|
|
|
|
post_znap_cmd = nullOff postsnap;
|
|
|
|
pre_znap_cmd = nullOff presnap;
|
|
|
|
recursive = onOff recursive;
|
|
|
|
src = dataset;
|
|
|
|
src_plan = plan;
|
|
|
|
tsformat = timestampFormat;
|
|
|
|
zend_delay = toString sendDelay;
|
2021-08-05 21:33:18 +00:00
|
|
|
} // foldr (a: b: a // b) {} (
|
2020-04-24 23:36:52 +00:00
|
|
|
map mkDestAttrs (builtins.attrValues destinations)
|
|
|
|
);
|
|
|
|
|
|
|
|
files = mapAttrs' (n: srcCfg: let
|
|
|
|
fileText = attrsToFile (mkSrcAttrs srcCfg);
|
|
|
|
in {
|
|
|
|
name = srcCfg.dataset;
|
|
|
|
value = pkgs.writeText (stripSlashes srcCfg.dataset) fileText;
|
|
|
|
}) cfg.zetup;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.znapzend = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "ZnapZend ZFS backup daemon");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
default = "debug";
|
|
|
|
example = "warning";
|
|
|
|
type = enum ["debug" "info" "warning" "err" "alert"];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The log level when logging to file. Any of debug, info, warning, err,
|
|
|
|
alert. Default in daemonized form is debug.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logTo = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "syslog::daemon";
|
|
|
|
example = "/var/log/znapzend.log";
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Where to log to (syslog::\<facility\> or \<filepath\>).
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
noDestroy = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Does all changes to the filesystem except destroy.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
autoCreation = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Automatically create the destination dataset if it does not exist.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
zetup = mkOption {
|
2020-09-25 04:45:31 +00:00
|
|
|
type = attrsOf srcType;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Znapzend configuration.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = {};
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
"tank/home" = {
|
|
|
|
# Make snapshots of tank/home every hour, keep those for 1 day,
|
|
|
|
# keep every days snapshot for 1 month, etc.
|
|
|
|
plan = "1d=>1h,1m=>1d,1y=>1m";
|
|
|
|
recursive = true;
|
|
|
|
# Send all those snapshots to john@example.com:rtank/john as well
|
|
|
|
destinations.remote = {
|
|
|
|
host = "john@example.com";
|
|
|
|
dataset = "rtank/john";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pure = mkOption {
|
|
|
|
type = bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Do not persist any stateful znapzend setups. If this option is
|
|
|
|
enabled, your previously set znapzend setups will be cleared and only
|
|
|
|
the ones defined with this module will be applied.
|
|
|
|
'';
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
features.oracleMode = mkEnableOption (lib.mdDoc ''
|
2020-05-15 21:57:56 +00:00
|
|
|
Destroy snapshots one by one instead of using one long argument list.
|
|
|
|
If source and destination are out of sync for a long time, you may have
|
|
|
|
so many snapshots to destroy that the argument gets is too long and the
|
|
|
|
command fails.
|
2022-09-09 14:08:57 +00:00
|
|
|
'');
|
|
|
|
features.recvu = mkEnableOption (lib.mdDoc ''
|
|
|
|
recvu feature which uses `-u` on the receiving end to keep the destination
|
2020-04-24 23:36:52 +00:00
|
|
|
filesystem unmounted.
|
2022-09-09 14:08:57 +00:00
|
|
|
'');
|
|
|
|
features.compressed = mkEnableOption (lib.mdDoc ''
|
|
|
|
compressed feature which adds the options `-Lce` to
|
|
|
|
the {command}`zfs send` command. When this is enabled, make
|
2020-04-24 23:36:52 +00:00
|
|
|
sure that both the sending and receiving pool have the same relevant
|
2022-12-28 21:21:41 +00:00
|
|
|
features enabled. Using `-c` will skip unnecessary
|
2022-09-09 14:08:57 +00:00
|
|
|
decompress-compress stages, `-L` is for large block
|
2020-04-24 23:36:52 +00:00
|
|
|
support and -e is for embedded data support. see
|
2022-09-09 14:08:57 +00:00
|
|
|
{manpage}`znapzend(1)`
|
|
|
|
and {manpage}`zfs(8)`
|
2020-04-24 23:36:52 +00:00
|
|
|
for more info.
|
2022-09-09 14:08:57 +00:00
|
|
|
'');
|
|
|
|
features.sendRaw = mkEnableOption (lib.mdDoc ''
|
|
|
|
sendRaw feature which adds the options `-w` to the
|
|
|
|
{command}`zfs send` command. For encrypted source datasets this
|
2020-05-15 21:57:56 +00:00
|
|
|
instructs zfs not to decrypt before sending which results in a remote
|
|
|
|
backup that can't be read without the encryption key/passphrase, useful
|
|
|
|
when the remote isn't fully trusted or not physically secure. This
|
|
|
|
option must be used consistently, raw incrementals cannot be based on
|
|
|
|
non-raw snapshots and vice versa.
|
2022-09-09 14:08:57 +00:00
|
|
|
'');
|
|
|
|
features.skipIntermediates = mkEnableOption (lib.mdDoc ''
|
2020-05-15 21:57:56 +00:00
|
|
|
Enable the skipIntermediates feature to send a single increment
|
|
|
|
between latest common snapshot and the newly made one. It may skip
|
|
|
|
several source snaps if the destination was offline for some time, and
|
|
|
|
it should skip snapshots not managed by znapzend. Normally for online
|
|
|
|
destinations, the new snapshot is sent as soon as it is created on the
|
|
|
|
source, so there are no automatic increments to skip.
|
2022-09-09 14:08:57 +00:00
|
|
|
'');
|
|
|
|
features.lowmemRecurse = mkEnableOption (lib.mdDoc ''
|
2020-05-15 21:57:56 +00:00
|
|
|
use lowmemRecurse on systems where you have too many datasets, so a
|
|
|
|
recursive listing of attributes to find backup plans exhausts the
|
2022-09-09 14:08:57 +00:00
|
|
|
memory available to {command}`znapzend`: instead, go the slower
|
2020-05-15 21:57:56 +00:00
|
|
|
way to first list all impacted dataset names, and then query their
|
|
|
|
configs one by one.
|
2022-09-09 14:08:57 +00:00
|
|
|
'');
|
|
|
|
features.zfsGetType = mkEnableOption (lib.mdDoc ''
|
|
|
|
use zfsGetType if your {command}`zfs get` supports a
|
|
|
|
`-t` argument for filtering by dataset type at all AND
|
2020-05-15 21:57:56 +00:00
|
|
|
lists properties for snapshots by default when recursing, so that there
|
|
|
|
is too much data to process while searching for backup plans.
|
|
|
|
If these two conditions apply to your system, the time needed for a
|
2022-09-09 14:08:57 +00:00
|
|
|
`--recursive` search for backup plans can literally
|
2020-05-15 21:57:56 +00:00
|
|
|
differ by hundreds of times (depending on the amount of snapshots in
|
|
|
|
that dataset tree... and a decent backup plan will ensure you have a lot
|
|
|
|
of those), so you would benefit from requesting this feature.
|
2022-09-09 14:08:57 +00:00
|
|
|
'');
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.znapzend ];
|
|
|
|
|
|
|
|
systemd.services = {
|
|
|
|
znapzend = {
|
|
|
|
description = "ZnapZend - ZFS Backup System";
|
|
|
|
wantedBy = [ "zfs.target" ];
|
|
|
|
after = [ "zfs.target" ];
|
|
|
|
|
|
|
|
path = with pkgs; [ zfs mbuffer openssh ];
|
|
|
|
|
|
|
|
preStart = optionalString cfg.pure ''
|
|
|
|
echo Resetting znapzend zetups
|
|
|
|
${pkgs.znapzend}/bin/znapzendzetup list \
|
|
|
|
| grep -oP '(?<=\*\*\* backup plan: ).*(?= \*\*\*)' \
|
|
|
|
| xargs -I{} ${pkgs.znapzend}/bin/znapzendzetup delete "{}"
|
|
|
|
'' + concatStringsSep "\n" (mapAttrsToList (dataset: config: ''
|
|
|
|
echo Importing znapzend zetup ${config} for dataset ${dataset}
|
|
|
|
${pkgs.znapzend}/bin/znapzendzetup import --write ${dataset} ${config} &
|
|
|
|
'') files) + ''
|
|
|
|
wait
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
# znapzendzetup --import apparently tries to connect to the backup
|
|
|
|
# host 3 times with a timeout of 30 seconds, leading to a startup
|
|
|
|
# delay of >90s when the host is down, which is just above the default
|
|
|
|
# service timeout of 90 seconds. Increase the timeout so it doesn't
|
|
|
|
# make the service fail in that case.
|
|
|
|
TimeoutStartSec = 180;
|
|
|
|
# Needs to have write access to ZFS
|
|
|
|
User = "root";
|
|
|
|
ExecStart = let
|
|
|
|
args = concatStringsSep " " [
|
|
|
|
"--logto=${cfg.logTo}"
|
|
|
|
"--loglevel=${cfg.logLevel}"
|
|
|
|
(optionalString cfg.noDestroy "--nodestroy")
|
|
|
|
(optionalString cfg.autoCreation "--autoCreation")
|
|
|
|
(optionalString (enabledFeatures != [])
|
|
|
|
"--features=${concatStringsSep "," enabledFeatures}")
|
|
|
|
]; in "${pkgs.znapzend}/bin/znapzend ${args}";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
meta.maintainers = with maintainers; [ infinisil SlothOfAnarchy ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|