From 7cee029fffeb1d3e09ef482de5ea684cc2ce42fb Mon Sep 17 00:00:00 2001 From: eyjhb Date: Thu, 8 Aug 2024 19:37:50 +0200 Subject: [PATCH] added zrepl for snapshots --- machines/gerd.nix | 2 + shared/modules/default.nix | 1 + shared/modules/zrepl.nix | 97 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 shared/modules/zrepl.nix diff --git a/machines/gerd.nix b/machines/gerd.nix index 8e7d583..0d7b3eb 100644 --- a/machines/gerd.nix +++ b/machines/gerd.nix @@ -29,6 +29,8 @@ in { }; }; + zrepl.enable = true; + ssh-on-boot.enable = true; platforms.hetzner = { diff --git a/shared/modules/default.nix b/shared/modules/default.nix index 5623c73..bff5d26 100644 --- a/shared/modules/default.nix +++ b/shared/modules/default.nix @@ -1,5 +1,6 @@ { imports = [ + ./zrepl.nix ./disko.nix ./state.nix ./ssh-luks-zfs-on-boot.nix diff --git a/shared/modules/zrepl.nix b/shared/modules/zrepl.nix new file mode 100644 index 0000000..0159be0 --- /dev/null +++ b/shared/modules/zrepl.nix @@ -0,0 +1,97 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) types; + + cfg = config.mine.zrepl; + + # helpers + zreplFilesystems = lib.listToAttrs ( + lib.forEach cfg.datasets (dataset: lib.nameValuePair dataset true) + ); + +in { + options = { + mine.zrepl = { + enable = lib.mkEnableOption "zrepl snapshot"; + + datasets = lib.mkOption { + type = types.listOf types.str; + default = [ + "rpool/safe<" + ]; + }; + }; + }; + + config = lib.mkIf cfg.enable { + services.zrepl = { + enable = true; + settings.jobs = [ + # push + { + name = "snapjob"; + type = "snap"; + + filesystems = zreplFilesystems; + + snapshotting = { + type = "periodic"; + interval = "5m"; + prefix = "zrepl_"; + }; + + pruning = { + keep = [ + { + type = "grid"; + regex = "^zrepl_.*"; + + # 1. keep all snapshots for 30 minutes + # 2. keep one every 15 minutes for 2 hours + # 3. keep one every hour for 1 day + grid = "1x30m(keep=all) | 8x15m | 24x1h"; + } + ]; + }; + } + ]; + }; + }; +} + +# { +# services.zrepl = { +# enable = true; +# settings.jobs = [ +# { +# type = "push"; +# name = "safesnapshots"; + +# filesystems = [ +# "rpool/safe<" +# ]; + +# snapshotting = { +# type = "periodic"; +# interval = "5m"; +# prefix = "zrepl_"; +# }; + +# pruning = { +# keep_sender = [ +# { +# type = "grid"; +# regex = "^zrepl_.*"; + +# # 1. keep all snapshots for 30 minutes +# # 2. keep one every 15 minutes for 2 hours +# # 3. keep one every hour for 1 day +# grid = "1x30m(keep=all) | 8x15m | 14x1d"; +# } +# ]; +# }; +# } +# ]; +# }; +# }