From 05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 9 Apr 2018 13:35:37 +0200 Subject: borg on odin --- custom/borgbackup.nix | 30 +++++++++++++++++++++++++----- custom/lvm-snapshots.nix | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'custom') 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; let cfg = config.services.borgbackup; + lvmPath = { + options = { + LV = mkOption { + type = types.str; + }; + VG = mkOption { + type = types.str; + }; + }; + }; + + pathType = if cfg.snapshots == "lvm" then types.submodule lvmPath else types.path; + + systemdPath = path: if cfg.snapshots == "lvm" then escapeSystemdPath "${path.VG}/${path.LV}" else escapeSystemdPath path; + targetOptions = { options = { repo = mkOption { @@ -12,7 +27,7 @@ let }; paths = mkOption { - type = types.listOf types.str; + type = types.listOf pathType; default = []; }; @@ -46,7 +61,7 @@ in { options = { services.borgbackup = { snapshots = mkOption { - type = types.nullOr (types.enum ["btrfs"]); + type = types.nullOr (types.enum ["btrfs" "lvm"]); default = null; }; @@ -63,8 +78,13 @@ in { config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; + + services.lvm-snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (systemdPath path) { + inherit (path) LV VG; + mountName = "snapshot-${systemdPath path}"; + }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); - systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${path}" { + systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${systemdPath path}" { wantedBy = [ "timers.target" ]; timerConfig = { @@ -102,7 +122,7 @@ in { --filter 'AME' \ --exclude-caches \ --keep-exclude-tags \ - --patterns-from .backup \ + --patterns-from .backup-${target} \ --one-file-system \ --compression auto,lzma \ ${tCfg.repo}::${cfg.prefix}$1-{utcnow} @@ -133,7 +153,7 @@ in { --lock-wait ${toString tCfg.lockWait} \ --list \ --stats \ - --prefix "${cfg.prefix}${path}" \ + --prefix "${cfg.prefix}${escapeSystemdPath path}" \ ${concatStringsSep " " args} \ ${tCfg.repo} '') 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 { mountPoint = mkOption { type = types.path; + readOnly = true; default = "/mnt"; }; }; -- cgit v1.2.3