summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-12-17 04:33:21 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-12-17 04:33:21 +0100
commit086035d82b049e8d8ca47c5cd5d3d2220833d4bc (patch)
treed797bd656b28d31f6f35a4c1f7c33a5b5dbb85c4
parent68a2cabc37625a0da1266cd90c693aba6df83e5b (diff)
downloadnixos-086035d82b049e8d8ca47c5cd5d3d2220833d4bc.tar
nixos-086035d82b049e8d8ca47c5cd5d3d2220833d4bc.tar.gz
nixos-086035d82b049e8d8ca47c5cd5d3d2220833d4bc.tar.bz2
nixos-086035d82b049e8d8ca47c5cd5d3d2220833d4bc.tar.xz
nixos-086035d82b049e8d8ca47c5cd5d3d2220833d4bc.zip
-rw-r--r--custom/borgbackup.nix39
1 files changed, 23 insertions, 16 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index 28dbba16..47714e83 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -54,14 +54,15 @@ in {
54 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { 54 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) {
55 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; 55 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true;
56 56
57 systemd.timers = listToAttrs (map ({ target, path }: nameValuePair "borgbackup-${target}@${path}" { 57 systemd.timers = listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${path}" {
58 wantedBy = [ "timers.target" ]; 58 wantedBy = [ "timers.target" ];
59 59
60 timerConfig = { 60 timerConfig = {
61 Persistent = true; 61 Persistent = false;
62 OnUnitInactiveSec = "6h"; 62 OnBootSec = tCfg.interval;
63 OnUnitInactiveSec = tCfg.interval;
63 }; 64 };
64 }) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path; }) tCfg.paths) cfg.targets))); 65 }) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path tCfg; }) tCfg.paths) cfg.targets)));
65 66
66 systemd.services = mapAttrs' (target: tCfg: nameValuePair "borgbackup-${target}@" (let 67 systemd.services = mapAttrs' (target: tCfg: nameValuePair "borgbackup-${target}@" (let
67 deps = flatten [ 68 deps = flatten [
@@ -74,20 +75,26 @@ in {
74 75
75 path = with pkgs; [borgbackup]; 76 path = with pkgs; [borgbackup];
76 77
77 script = '' 78 script = let
78 borg create \ 79 borgCmd = ''
79 --stats \ 80 borg create \
80 --list \ 81 --stats \
81 --filter 'AME' \ 82 --list \
82 --exclude-caches \ 83 --filter 'AME' \
83 --keep-exclude-tags \ 84 --exclude-caches \
84 --patterns-from .backup \ 85 --keep-exclude-tags \
85 --one-file-system \ 86 --patterns-from .backup \
86 --compression auto,lzma \ 87 --one-file-system \
87 ${target}::${cfg.prefix}$1-{utcnow} 88 --compression auto,lzma \
88 ''; 89 ${target}::${cfg.prefix}$1-{utcnow}
90 '';
91 in if tCfg.lock == null then borgCmd else "flock -xo /var/lock/${tCfg.lock} ${borgCmd}";
89 scriptArgs = "%i"; 92 scriptArgs = "%i";
90 93
94 unitConfig = {
95 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock";
96 };
97
91 serviceConfig = { 98 serviceConfig = {
92 Type = "oneshot"; 99 Type = "oneshot";
93 WorkingDirectory = if (cfg.snapshots == null) then "%p" else "/mnt/snapshot-%i"; 100 WorkingDirectory = if (cfg.snapshots == null) then "%p" else "/mnt/snapshot-%i";