Merge pull request #65407 from alunduil/add-zfs-replication
Add zfs replication
This commit is contained in:
commit
d02ead41f8
90
nixos/modules/services/backup/zfs-replication.nix
Normal file
90
nixos/modules/services/backup/zfs-replication.nix
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
{ lib, pkgs, config, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.zfs.autoReplication;
|
||||||
|
recursive = optionalString cfg.recursive " --recursive";
|
||||||
|
followDelete = optionalString cfg.followDelete " --follow-delete";
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
services.zfs.autoReplication = {
|
||||||
|
enable = mkEnableOption "ZFS snapshot replication.";
|
||||||
|
|
||||||
|
followDelete = mkOption {
|
||||||
|
description = "Remove remote snapshots that don't have a local correspondant.";
|
||||||
|
default = true;
|
||||||
|
type = types.bool;
|
||||||
|
};
|
||||||
|
|
||||||
|
host = mkOption {
|
||||||
|
description = "Remote host where snapshots should be sent.";
|
||||||
|
example = "example.com";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
identityFilePath = mkOption {
|
||||||
|
description = "Path to SSH key used to login to host.";
|
||||||
|
example = "/home/username/.ssh/id_rsa";
|
||||||
|
type = types.path;
|
||||||
|
};
|
||||||
|
|
||||||
|
localFilesystem = mkOption {
|
||||||
|
description = "Local ZFS fileystem from which snapshots should be sent. Defaults to the attribute name.";
|
||||||
|
example = "pool/file/path";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
remoteFilesystem = mkOption {
|
||||||
|
description = "Remote ZFS filesystem where snapshots should be sent.";
|
||||||
|
example = "pool/file/path";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
recursive = mkOption {
|
||||||
|
description = "Recursively discover snapshots to send.";
|
||||||
|
default = true;
|
||||||
|
type = types.bool;
|
||||||
|
};
|
||||||
|
|
||||||
|
username = mkOption {
|
||||||
|
description = "Username used by SSH to login to remote host.";
|
||||||
|
example = "username";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
environment.systemPackages = [
|
||||||
|
pkgs.lz4
|
||||||
|
];
|
||||||
|
|
||||||
|
systemd.services."zfs-replication" = {
|
||||||
|
after = [
|
||||||
|
"zfs-snapshot-daily.service"
|
||||||
|
"zfs-snapshot-frequent.service"
|
||||||
|
"zfs-snapshot-hourly.service"
|
||||||
|
"zfs-snapshot-monthly.service"
|
||||||
|
"zfs-snapshot-weekly.service"
|
||||||
|
];
|
||||||
|
description = "ZFS Snapshot Replication";
|
||||||
|
documentation = [
|
||||||
|
"https://github.com/alunduil/zfs-replicate"
|
||||||
|
];
|
||||||
|
restartIfChanged = false;
|
||||||
|
serviceConfig.ExecStart = "${pkgs.zfs-replicate}/bin/zfs-replicate${recursive} -l ${escapeShellArg cfg.username} -i ${escapeShellArg cfg.identityFilePath}${followDelete} ${escapeShellArg cfg.host} ${escapeShellArg cfg.remoteFilesystem} ${escapeShellArg cfg.localFilesystem}";
|
||||||
|
wantedBy = [
|
||||||
|
"zfs-snapshot-daily.service"
|
||||||
|
"zfs-snapshot-frequent.service"
|
||||||
|
"zfs-snapshot-hourly.service"
|
||||||
|
"zfs-snapshot-monthly.service"
|
||||||
|
"zfs-snapshot-weekly.service"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
maintainers = with lib.maintainers; [ alunduil ];
|
||||||
|
};
|
||||||
|
}
|
22
pkgs/development/python-modules/stringcase/default.nix
Normal file
22
pkgs/development/python-modules/stringcase/default.nix
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{ buildPythonPackage, fetchPypi, stdenv
|
||||||
|
}:
|
||||||
|
|
||||||
|
buildPythonPackage rec {
|
||||||
|
pname = "stringcase";
|
||||||
|
version = "1.2.0";
|
||||||
|
|
||||||
|
src = fetchPypi {
|
||||||
|
inherit pname version;
|
||||||
|
sha256 = "023hv3gknblhf9lx5kmkcchzmbhkdhmsnknkv7lfy20rcs06k828";
|
||||||
|
};
|
||||||
|
|
||||||
|
# PyPi package does not include tests.
|
||||||
|
doCheck = false;
|
||||||
|
|
||||||
|
meta = with stdenv.lib; {
|
||||||
|
homepage = https://github.com/okunishinishi/python-stringcase;
|
||||||
|
description = "Convert string cases between camel case, pascal case, snake case etc…";
|
||||||
|
license = licenses.mit;
|
||||||
|
maintainers = with maintainers; [ alunduil ];
|
||||||
|
};
|
||||||
|
}
|
42
pkgs/tools/backup/zfs-replicate/default.nix
Normal file
42
pkgs/tools/backup/zfs-replicate/default.nix
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{ buildPythonApplication, click, fetchPypi, hypothesis, mypy, pytest
|
||||||
|
, pytestcov, pytestrunner, stdenv, stringcase
|
||||||
|
}:
|
||||||
|
|
||||||
|
buildPythonApplication rec {
|
||||||
|
pname = "zfs-replicate";
|
||||||
|
version = "1.1.11";
|
||||||
|
|
||||||
|
src = fetchPypi {
|
||||||
|
inherit pname version;
|
||||||
|
sha256 = "0386xc6rw6bhzw2a08g90afb3snqhm1ikx65bjfh22ha69fwmga8";
|
||||||
|
};
|
||||||
|
|
||||||
|
checkInputs = [
|
||||||
|
hypothesis
|
||||||
|
mypy
|
||||||
|
pytest
|
||||||
|
pytestcov
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
pytestrunner
|
||||||
|
];
|
||||||
|
|
||||||
|
propagatedBuildInputs = [
|
||||||
|
click
|
||||||
|
stringcase
|
||||||
|
];
|
||||||
|
|
||||||
|
doCheck = true;
|
||||||
|
|
||||||
|
checkPhase = ''
|
||||||
|
pytest --doctest-modules
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with stdenv.lib; {
|
||||||
|
homepage = https://github.com/alunduil/zfs-replicate;
|
||||||
|
description = "ZFS Snapshot Replication";
|
||||||
|
license = licenses.bsd2;
|
||||||
|
maintainers = with maintainers; [ alunduil ];
|
||||||
|
};
|
||||||
|
}
|
@ -24570,4 +24570,6 @@ in
|
|||||||
dapper = callPackage ../development/tools/dapper { };
|
dapper = callPackage ../development/tools/dapper { };
|
||||||
|
|
||||||
kube3d = callPackage ../applications/networking/cluster/kube3d {};
|
kube3d = callPackage ../applications/networking/cluster/kube3d {};
|
||||||
|
|
||||||
|
zfs-replicate = python3Packages.callPackage ../tools/backup/zfs-replicate { };
|
||||||
}
|
}
|
||||||
|
@ -6088,6 +6088,8 @@ in {
|
|||||||
pydantic = callPackage ../development/python-modules/pydantic { };
|
pydantic = callPackage ../development/python-modules/pydantic { };
|
||||||
|
|
||||||
fastapi = callPackage ../development/python-modules/fastapi { };
|
fastapi = callPackage ../development/python-modules/fastapi { };
|
||||||
|
|
||||||
|
stringcase = callPackage ../development/python-modules/stringcase { };
|
||||||
});
|
});
|
||||||
|
|
||||||
in fix' (extends overrides packages)
|
in fix' (extends overrides packages)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user