diff options
Diffstat (limited to 'modules/backup/snapshot.nix')
| -rw-r--r-- | modules/backup/snapshot.nix | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/modules/backup/snapshot.nix b/modules/backup/snapshot.nix index 91076cf..a1fba73 100644 --- a/modules/backup/snapshot.nix +++ b/modules/backup/snapshot.nix @@ -6,17 +6,25 @@ ... }: let - instanceType = lib.types.submodule { + snapshotType = lib.types.submodule { options = { - path = lib.mkOption { - type = lib.types.str; - default = "/persistent"; - description = "snapshoted path for kopia instance."; + paths = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "snapshoted paths"; }; schedule = lib.mkOption { type = lib.types.str; - default = "daily"; - description = "Snapshot schedule for the Kopia instance."; + default = "*-*-* 4:00:00"; + description = "Snapshot schedule"; + }; + }; + }; + + instanceType = lib.types.submodule { + options = { + snapshots = lib.mkOption { + type = snapshotType; }; }; }; @@ -37,9 +45,11 @@ in "kopia-repository-${name}.service" ]; after = [ "kopia-repository-${name}.service" ]; - script = '' - ${pkgs.kopia}/bin/kopia snapshot create ${instance.path} --description "Snapshot for ${name}" - ''; + script = lib.strings.concatLines ( + lib.lists.forEach instance.snapshots.paths (x: '' + ${pkgs.kopia}/bin/kopia snapshot create ${x} --description "Snapshot for ${name}" + '') + ); serviceConfig = { Type = "simple"; User = "${instance.user}"; @@ -49,13 +59,15 @@ in Restart = "on-failure"; # wait 30 seconds before restarting RestartSec = "30"; - # limit the number of restarts to 5 in 1 day - StartLimitInterval = "1d"; - StartLimitBurst = "5"; # lower priority Nice = "-19"; IOSchedulingClass = "idle"; }; + unitConfig = { + # limit the number of restarts to 5 in 1 day + StartLimitInterval = "1d"; + StartLimitBurst = "5"; + }; }; mkSnapshotTimer = name: instance: @@ -63,7 +75,7 @@ in description = "Kopia S3 snapshot timer"; wantedBy = [ "timers.target" ]; timerConfig = { - OnCalendar = instance.schedule; + OnCalendar = instance.snapshots.schedule; }; }; in |
