Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/zrepl: init #113090

Merged
merged 1 commit into from Feb 24, 2021
Merged

nixos/zrepl: init #113090

merged 1 commit into from Feb 24, 2021

Conversation

cole-h
Copy link
Member

@cole-h cole-h commented Feb 14, 2021

Motivation for this change

People have expressed interest in a zrepl module for NixOS, so I've done the bare minimum to get one up and running. The module conforms to RFC 42 which made it much easier to get the module up and running, considering there was no real "logic" to implement.

Note that I have tested none of the functionality of the service yet, and thus am opening this as a draft.

I tried to have the config be validated at build time, but that doesn't work if you use a config that requires access to certs (the configcheck subcommand actually tries to read the file).

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

cc potentially interested parties: @grahamc @ElvishJerricco @infinisil

Example config translated from the snap example:

{
    services.zrepl = {
        enable = true;
        settings = {
            jobs = [
                {
                    name = "snapjob";
                    type = "snap";
                    filesystems = {
                        "tank/frequently_changed<" = true;
                    };

                    snapshotting = {
                        type = "periodic";
                        interval = "2m";
                        prefix = "zrepl_snapjob_";
                    };

                    pruning = {
                        keep = [
                            { type = "last_n"; count = 60; }
                        ];
                    };
                }
            ];
        };
    };
}

@cole-h
Copy link
Member Author

cole-h commented Feb 18, 2021

Depends on #113540 for the package.

@cole-h cole-h marked this pull request as ready for review February 21, 2021 03:53
@cole-h cole-h changed the title WIP: nixos/zrepl: init nixos/zrepl: init Feb 21, 2021
@cole-h cole-h force-pushed the zrepl branch 2 times, most recently from 594b033 to fc1e78a Compare February 21, 2021 04:03
@cole-h
Copy link
Member Author

cole-h commented Feb 21, 2021

Ran this on a test dataset and it seems to work fine.

$ zfs list tank/test -t snapshot -r
tank/test@zrepl_snapjob_20210221_014828_000       148K      -      196K  -
tank/test@zrepl_snapjob_20210221_020328_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_021828_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_023328_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_024828_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_030328_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_031828_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_033328_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_034512_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_035012_000         0B      -      236K  -
tank/test@zrepl_snapjob_20210221_035512_000         0B      -      236K  -
tank/test/dir@zrepl_snapjob_20210221_015328_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_021828_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_023328_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_024828_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_030328_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_031828_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_033328_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_034512_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_035012_000     0B      -      196K  -
tank/test/dir@zrepl_snapjob_20210221_035512_000     0B      -      196K  -

with config:

{ lib, ... }:
{
  services.zrepl = {
    enable = true;
    settings = {
      global = {
        logging = [{
          type = "syslog";
          level = "info";
          format = "human";
        }];
      };

      jobs = [
        {
          name = "snapjob";
          type = "snap";
          filesystems = {
            "tank/test<" = true;
          };

          snapshotting = {
            type = "periodic";
            interval = "5m";
            prefix = "zrepl_snapjob_";
          };

          pruning = {
            keep = [
              {
                type = "grid";
                regex = "^zrepl_.*";
                grid = lib.concatStringsSep " | " [
                  "3x5m" # 3 buckets of 1 snapshot every 5 minutes (15 minutes total)
                  "16x15m" # 16 buckets of 1 snapshot every 15 minutes (4 hours total)
                  "6x4h" # 6 buckets of 1 snapshot every 4 hours (1 day total)
                  "7x1d" # 7 buckets of 1 snapshot every 1 day (1 week total)
                  "4x1w" # 4 buckets of 1 snapshot every 1 week (~1 month total)
                  "12x30d" # 12 buckets of 1 snapshot every 30 days (~1 year total)
                  # (roughly) translated from znapzend config:
                  # plan = "15min=>5min,4h=>15min,1d=>4h,1w=>1d,1m=>1w,1y=>1m";
                ];
              }
            ];
          };
        }
      ];
    };
  };
}

One thing to keep in mind is that zrepl doesn't support month or year as an interval, so you must use something like 30d or 365d (or whatever conversion you prefer) in those cases.

@cole-h
Copy link
Member Author

cole-h commented Feb 21, 2021

@ofborg eval

@tomberek
Copy link
Contributor

As a test; added this service to a copy of nixos/tests/zfs.nix and started without issues, but I did not test zrepl-specific functionality.

zrepl is a ZFS backup and replication tool written in Go.
Copy link
Member

@grahamc grahamc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks! I'm looking forward to using this on haumea!

@cole-h cole-h merged commit 1b37f66 into NixOS:master Feb 24, 2021
@cole-h cole-h deleted the zrepl branch February 24, 2021 19:56
@Baughn
Copy link
Contributor

Baughn commented Mar 1, 2021

@cole-h

I never got around to finishing it, but if you want to build something with structured config options, here's a start: https://github.com/Baughn/machine-config/tree/master/zrepl

@Maxwell-lt
Copy link
Contributor

@Baughn I'm guessing you meant to link this file: https://github.com/Baughn/machine-config/blob/master/modules/zrepl.nix

I'm also using Baughn's zrepl module, though I added the ability to specify the name of a push job separately from the server CN, which is required if you want multiple push jobs to the same sink, to support multiple root pools (in my case, a fast SSD pool and a "slow" HDD pool)
https://github.com/Maxwell-lt/machine-configuration/blob/master/services/zrepl.nix

@cole-h
Copy link
Member Author

cole-h commented Mar 1, 2021

tbh, I'm quite happy with this "unstructured" config version -- it's easily extendable if they ever add or remove things from their configuration format without needing to touch the module itself. But if you feel like structuring / typing this, I'll gladly review a PR :)

(I just don't feel the need to do submit a PR to that effect, myself.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants