2020-04-24 23:36:52 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }: let
|
|
|
|
inherit (import ./ssh-keys.nix pkgs)
|
|
|
|
snakeOilPrivateKey snakeOilPublicKey;
|
|
|
|
|
|
|
|
commonConfig = { pkgs, ... }: {
|
|
|
|
virtualisation.emptyDiskImages = [ 2048 ];
|
|
|
|
boot.supportedFilesystems = [ "zfs" ];
|
|
|
|
environment.systemPackages = [ pkgs.parted ];
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
name = "sanoid";
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = [ lopsided98 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
source = { ... }: {
|
|
|
|
imports = [ commonConfig ];
|
|
|
|
networking.hostId = "daa82e91";
|
|
|
|
|
|
|
|
programs.ssh.extraConfig = ''
|
|
|
|
UserKnownHostsFile=/dev/null
|
|
|
|
StrictHostKeyChecking=no
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.sanoid = {
|
|
|
|
enable = true;
|
|
|
|
templates.test = {
|
|
|
|
hourly = 12;
|
|
|
|
daily = 1;
|
|
|
|
monthly = 1;
|
|
|
|
yearly = 1;
|
|
|
|
|
|
|
|
autosnap = true;
|
|
|
|
};
|
2021-07-03 03:11:41 +00:00
|
|
|
datasets."pool/sanoid".use_template = [ "test" ];
|
2021-05-28 09:39:13 +00:00
|
|
|
extraArgs = [ "--verbose" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.syncoid = {
|
|
|
|
enable = true;
|
2020-10-27 00:29:36 +00:00
|
|
|
sshKey = "/var/lib/syncoid/id_ecdsa";
|
2021-05-28 09:39:13 +00:00
|
|
|
commands = {
|
|
|
|
# Sync snapshot taken by sanoid
|
|
|
|
"pool/sanoid" = {
|
|
|
|
target = "root@target:pool/sanoid";
|
|
|
|
extraArgs = [ "--no-sync-snap" ];
|
|
|
|
};
|
|
|
|
# Take snapshot and sync
|
|
|
|
"pool/syncoid".target = "root@target:pool/syncoid";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
target = { ... }: {
|
|
|
|
imports = [ commonConfig ];
|
|
|
|
networking.hostId = "dcf39d36";
|
|
|
|
|
|
|
|
services.openssh.enable = true;
|
|
|
|
users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
source.succeed(
|
2021-05-28 09:39:13 +00:00
|
|
|
"mkdir /mnt",
|
2020-04-24 23:36:52 +00:00
|
|
|
"parted --script /dev/vdb -- mklabel msdos mkpart primary 1024M -1s",
|
|
|
|
"udevadm settle",
|
2021-05-28 09:39:13 +00:00
|
|
|
"zpool create pool -R /mnt /dev/vdb1",
|
|
|
|
"zfs create pool/sanoid",
|
|
|
|
"zfs create pool/syncoid",
|
2020-04-24 23:36:52 +00:00
|
|
|
"udevadm settle",
|
|
|
|
)
|
|
|
|
target.succeed(
|
2021-05-28 09:39:13 +00:00
|
|
|
"mkdir /mnt",
|
2020-04-24 23:36:52 +00:00
|
|
|
"parted --script /dev/vdb -- mklabel msdos mkpart primary 1024M -1s",
|
|
|
|
"udevadm settle",
|
2021-05-28 09:39:13 +00:00
|
|
|
"zpool create pool -R /mnt /dev/vdb1",
|
2020-04-24 23:36:52 +00:00
|
|
|
"udevadm settle",
|
|
|
|
)
|
|
|
|
|
|
|
|
source.succeed(
|
2020-10-27 00:29:36 +00:00
|
|
|
"mkdir -m 700 -p /var/lib/syncoid",
|
|
|
|
"cat '${snakeOilPrivateKey}' > /var/lib/syncoid/id_ecdsa",
|
|
|
|
"chmod 600 /var/lib/syncoid/id_ecdsa",
|
|
|
|
"chown -R syncoid:syncoid /var/lib/syncoid/",
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
|
2021-05-28 09:39:13 +00:00
|
|
|
# Take snapshot with sanoid
|
|
|
|
source.succeed("touch /mnt/pool/sanoid/test.txt")
|
2020-04-24 23:36:52 +00:00
|
|
|
source.systemctl("start --wait sanoid.service")
|
|
|
|
|
2021-05-28 09:39:13 +00:00
|
|
|
# Sync snapshots
|
2020-04-24 23:36:52 +00:00
|
|
|
target.wait_for_open_port(22)
|
2021-05-28 09:39:13 +00:00
|
|
|
source.succeed("touch /mnt/pool/syncoid/test.txt")
|
2020-04-24 23:36:52 +00:00
|
|
|
source.systemctl("start --wait syncoid.service")
|
2021-05-28 09:39:13 +00:00
|
|
|
target.succeed("cat /mnt/pool/sanoid/test.txt")
|
|
|
|
target.succeed("cat /mnt/pool/syncoid/test.txt")
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
})
|