diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-09 13:35:37 +0200 | 
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-09 13:35:37 +0200 | 
| commit | 05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d (patch) | |
| tree | d3895f51a8d9e7dc08ac2947ce4a1c64a452ef59 | |
| parent | bb87c21224a1aad29b52267d3be710aac87871d1 (diff) | |
| download | nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar.gz nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar.bz2 nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar.xz nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.zip | |
borg on odin
| -rw-r--r-- | custom/borgbackup.nix | 30 | ||||
| -rw-r--r-- | custom/lvm-snapshots.nix | 1 | ||||
| -rw-r--r-- | hel.nix | 8 | ||||
| -rw-r--r-- | odin.nix | 14 | 
4 files changed, 39 insertions, 14 deletions
| diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix index 91de89a5..77e7637a 100644 --- a/custom/borgbackup.nix +++ b/custom/borgbackup.nix | |||
| @@ -5,6 +5,21 @@ with lib; | |||
| 5 | let | 5 | let | 
| 6 | cfg = config.services.borgbackup; | 6 | cfg = config.services.borgbackup; | 
| 7 | 7 | ||
| 8 | lvmPath = { | ||
| 9 | options = { | ||
| 10 | LV = mkOption { | ||
| 11 | type = types.str; | ||
| 12 | }; | ||
| 13 | VG = mkOption { | ||
| 14 | type = types.str; | ||
| 15 | }; | ||
| 16 | }; | ||
| 17 | }; | ||
| 18 | |||
| 19 | pathType = if cfg.snapshots == "lvm" then types.submodule lvmPath else types.path; | ||
| 20 | |||
| 21 | systemdPath = path: if cfg.snapshots == "lvm" then escapeSystemdPath "${path.VG}/${path.LV}" else escapeSystemdPath path; | ||
| 22 | |||
| 8 | targetOptions = { | 23 | targetOptions = { | 
| 9 | options = { | 24 | options = { | 
| 10 | repo = mkOption { | 25 | repo = mkOption { | 
| @@ -12,7 +27,7 @@ let | |||
| 12 | }; | 27 | }; | 
| 13 | 28 | ||
| 14 | paths = mkOption { | 29 | paths = mkOption { | 
| 15 | type = types.listOf types.str; | 30 | type = types.listOf pathType; | 
| 16 | default = []; | 31 | default = []; | 
| 17 | }; | 32 | }; | 
| 18 | 33 | ||
| @@ -46,7 +61,7 @@ in { | |||
| 46 | options = { | 61 | options = { | 
| 47 | services.borgbackup = { | 62 | services.borgbackup = { | 
| 48 | snapshots = mkOption { | 63 | snapshots = mkOption { | 
| 49 | type = types.nullOr (types.enum ["btrfs"]); | 64 | type = types.nullOr (types.enum ["btrfs" "lvm"]); | 
| 50 | default = null; | 65 | default = null; | 
| 51 | }; | 66 | }; | 
| 52 | 67 | ||
| @@ -63,8 +78,13 @@ in { | |||
| 63 | 78 | ||
| 64 | config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { | 79 | config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { | 
| 65 | services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; | 80 | services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; | 
| 81 | |||
| 82 | services.lvm-snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (systemdPath path) { | ||
| 83 | inherit (path) LV VG; | ||
| 84 | mountName = "snapshot-${systemdPath path}"; | ||
| 85 | }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); | ||
| 66 | 86 | ||
| 67 | systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${path}" { | 87 | systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${systemdPath path}" { | 
| 68 | wantedBy = [ "timers.target" ]; | 88 | wantedBy = [ "timers.target" ]; | 
| 69 | 89 | ||
| 70 | timerConfig = { | 90 | timerConfig = { | 
| @@ -102,7 +122,7 @@ in { | |||
| 102 | --filter 'AME' \ | 122 | --filter 'AME' \ | 
| 103 | --exclude-caches \ | 123 | --exclude-caches \ | 
| 104 | --keep-exclude-tags \ | 124 | --keep-exclude-tags \ | 
| 105 | --patterns-from .backup \ | 125 | --patterns-from .backup-${target} \ | 
| 106 | --one-file-system \ | 126 | --one-file-system \ | 
| 107 | --compression auto,lzma \ | 127 | --compression auto,lzma \ | 
| 108 | ${tCfg.repo}::${cfg.prefix}$1-{utcnow} | 128 | ${tCfg.repo}::${cfg.prefix}$1-{utcnow} | 
| @@ -133,7 +153,7 @@ in { | |||
| 133 | --lock-wait ${toString tCfg.lockWait} \ | 153 | --lock-wait ${toString tCfg.lockWait} \ | 
| 134 | --list \ | 154 | --list \ | 
| 135 | --stats \ | 155 | --stats \ | 
| 136 | --prefix "${cfg.prefix}${path}" \ | 156 | --prefix "${cfg.prefix}${escapeSystemdPath path}" \ | 
| 137 | ${concatStringsSep " " args} \ | 157 | ${concatStringsSep " " args} \ | 
| 138 | ${tCfg.repo} | 158 | ${tCfg.repo} | 
| 139 | '') tCfg.prune); | 159 | '') tCfg.prune); | 
| diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix index 159fe98b..ea69e1ff 100644 --- a/custom/lvm-snapshots.nix +++ b/custom/lvm-snapshots.nix | |||
| @@ -50,6 +50,7 @@ in { | |||
| 50 | 50 | ||
| 51 | mountPoint = mkOption { | 51 | mountPoint = mkOption { | 
| 52 | type = types.path; | 52 | type = types.path; | 
| 53 | readOnly = true; | ||
| 53 | default = "/mnt"; | 54 | default = "/mnt"; | 
| 54 | }; | 55 | }; | 
| 55 | }; | 56 | }; | 
| @@ -523,9 +523,9 @@ | |||
| 523 | targets = { | 523 | targets = { | 
| 524 | "odin" = { | 524 | "odin" = { | 
| 525 | repo = "borg.odin:/srv/backup/borg"; | 525 | repo = "borg.odin:/srv/backup/borg"; | 
| 526 | paths = [ "home-gkleen" ]; | 526 | paths = [ "/home/gkleen" ]; | 
| 527 | prune = { | 527 | prune = { | 
| 528 | "home-gkleen" = | 528 | "/home/gkleen" = | 
| 529 | [ "--keep-within 24H" | 529 | [ "--keep-within 24H" | 
| 530 | "--keep-daily 31" | 530 | "--keep-daily 31" | 
| 531 | "--keep-monthly 12" | 531 | "--keep-monthly 12" | 
| @@ -535,9 +535,9 @@ | |||
| 535 | }; | 535 | }; | 
| 536 | "munin" = { | 536 | "munin" = { | 
| 537 | repo = "borg.munin:borg"; | 537 | repo = "borg.munin:borg"; | 
| 538 | paths = [ "home-gkleen" ]; | 538 | paths = [ "/home/gkleen" ]; | 
| 539 | prune = { | 539 | prune = { | 
| 540 | "home-gkleen" = | 540 | "/home/gkleen" = | 
| 541 | [ "--keep-within 24H" | 541 | [ "--keep-within 24H" | 
| 542 | "--keep-daily 31" | 542 | "--keep-daily 31" | 
| 543 | "--keep-monthly 12" | 543 | "--keep-monthly 12" | 
| @@ -148,11 +148,15 @@ | |||
| 148 | networks = ["127.0.0.0/8" "[::ffff:127.0.0.0]/104" "[::1]/128" "10.141.0.0/16"]; | 148 | networks = ["127.0.0.0/8" "[::ffff:127.0.0.0]/104" "[::1]/128" "10.141.0.0/16"]; | 
| 149 | }; | 149 | }; | 
| 150 | 150 | ||
| 151 | services.lvm-snapshots = { | 151 | services.borgbackup = { | 
| 152 | snapshots = { | 152 | snapshots = "lvm"; | 
| 153 | mail = { | 153 | prefix = "automatic.yggdrasil.asgard.odin."; | 
| 154 | LV = "mail"; | 154 | targets = { | 
| 155 | VG = "raid6"; | 155 | "munin" = { | 
| 156 | repo = "borg.munin:borg"; | ||
| 157 | paths = [ | ||
| 158 | { VG = "raid6"; LV = "mail"; } | ||
| 159 | ]; | ||
| 156 | }; | 160 | }; | 
| 157 | }; | 161 | }; | 
| 158 | }; | 162 | }; | 
