summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-12-17 14:22:10 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-12-17 14:22:10 +0100
commitb115168c15be41055343dba3a6e37d0e4ffd4590 (patch)
treea2d6ba007d64243ec263e52594701d465ceac35c
parenteb13c2f4e7c2891548a8939575a5ee95ead67d15 (diff)
downloadnixos-b115168c15be41055343dba3a6e37d0e4ffd4590.tar
nixos-b115168c15be41055343dba3a6e37d0e4ffd4590.tar.gz
nixos-b115168c15be41055343dba3a6e37d0e4ffd4590.tar.bz2
nixos-b115168c15be41055343dba3a6e37d0e4ffd4590.tar.xz
nixos-b115168c15be41055343dba3a6e37d0e4ffd4590.zip
-rw-r--r--custom/borgbackup.nix23
-rw-r--r--hel.nix16
2 files changed, 33 insertions, 6 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index 222b1999..c08168ed 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -16,6 +16,11 @@ let
16 default = []; 16 default = [];
17 }; 17 };
18 18
19 prune = mkOption {
20 type = types.attrsOf (types.listOf types.str);
21 default = {};
22 };
23
19 interval = mkOption { 24 interval = mkOption {
20 type = types.str; 25 type = types.str;
21 default = "6h"; 26 default = "6h";
@@ -54,7 +59,7 @@ in {
54 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { 59 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) {
55 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; 60 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true;
56 61
57 systemd.timers = listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${path}" { 62 systemd.timers = listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}-${path}" {
58 wantedBy = [ "timers.target" ]; 63 wantedBy = [ "timers.target" ];
59 64
60 timerConfig = { 65 timerConfig = {
@@ -64,9 +69,9 @@ in {
64 }; 69 };
65 }) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path tCfg; }) tCfg.paths) cfg.targets))); 70 }) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path tCfg; }) tCfg.paths) cfg.targets)));
66 71
67 systemd.services = mapAttrs' (target: tCfg: nameValuePair "borgbackup-${target}@" (let 72 systemd.services = listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${path}" (let
68 deps = flatten [ 73 deps = flatten [
69 (optional (cfg.snapshots == "btrfs") "btrfs-snapshot@%i.service") 74 (optional (cfg.snapshots == "btrfs") "btrfs-snapshot@%p.service")
70 (optional tCfg.network "network-online.target") 75 (optional tCfg.network "network-online.target")
71 ]; 76 ];
72 in { 77 in {
@@ -87,10 +92,16 @@ in {
87 --patterns-from .backup \ 92 --patterns-from .backup \
88 --one-file-system \ 93 --one-file-system \
89 --compression auto,lzma \ 94 --compression auto,lzma \
90 ${tCfg.repo}::${cfg.prefix}$1-{utcnow} 95 ${tCfg.repo}::${cfg.prefix}${path}-{utcnow}
91 ''; 96 '';
92 in if tCfg.lock == null then borgCmd else "flock -xo /var/lock/${tCfg.lock} ${borgCmd}"; 97 in if tCfg.lock == null then borgCmd else "flock -xo /var/lock/${tCfg.lock} ${borgCmd}";
93 scriptArgs = "%i"; 98
99 preStop = mkIf (hasAttr path tCfg.prune) ''
100 borg prune \
101 --prefix "${tcfg.prefix}${path}" \
102 ${concatStringsSep " " tCfg.prune."${path}"} \
103 ${tCfg.repo}
104 '';
94 105
95 unitConfig = { 106 unitConfig = {
96 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock"; 107 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock";
@@ -104,6 +115,6 @@ in {
104 IOSchedulingPriority = 7; 115 IOSchedulingPriority = 7;
105 SuccessExitStatus = [1 2]; 116 SuccessExitStatus = [1 2];
106 }; 117 };
107 })) cfg.targets; 118 }))) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path tCfg; }) tCfg.paths) cfg.targets)));
108 }; 119 };
109} 120}
diff --git a/hel.nix b/hel.nix
index 68d6df08..1165e4fa 100644
--- a/hel.nix
+++ b/hel.nix
@@ -532,10 +532,26 @@
532 "odin" = { 532 "odin" = {
533 repo = "borg.odin:/srv/backup/borg"; 533 repo = "borg.odin:/srv/backup/borg";
534 paths = [ "home-gkleen" ]; 534 paths = [ "home-gkleen" ];
535 prune = {
536 "home-gkleen" =
537 [ "--keep-within 24H"
538 "--keep-daily 31"
539 "--keep-monthly 12"
540 "--keep-yearly -1"
541 ];
542 };
535 }; 543 };
536 "munin" = { 544 "munin" = {
537 repo = "borg.munin:borg"; 545 repo = "borg.munin:borg";
538 paths = [ "home-gkleen" ]; 546 paths = [ "home-gkleen" ];
547 prune = {
548 "home-gkleen" =
549 [ "--keep-within 24H"
550 "--keep-daily 31"
551 "--keep-monthly 12"
552 "--keep-yearly -1"
553 ];
554 };
539 }; 555 };
540 }; 556 };
541 }; 557 };