diff options
| author | Max Audron <audron@cocaine.farm> | 2026-01-07 15:28:01 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2026-01-07 15:28:01 +0100 |
| commit | 84739ac2345265e518a50bc2e9a239eb442e6e22 (patch) | |
| tree | e289c856e5465f0c713e97a0ba86e1f734c3484e /modules/backup/snapshot.nix | |
| parent | add kopia module (diff) | |
setup backups for mail
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 |
