blob: e800340df6e64e047e7326c168959b1bb3b778ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
{
name = "zrepl";
nodes = {
source =
{ nodes, pkgs, ... }:
{
config = {
# Prerequisites for ZFS and tests.
virtualisation.emptyDiskImages = [
2048
];
boot.supportedFilesystems = [ "zfs" ];
environment.systemPackages = [
pkgs.parted
pkgs.zrepl
];
networking.firewall.allowedTCPPorts = [ 8888 ];
networking.hostId = "deadbeef";
services.zrepl = {
enable = true;
settings = {
# Enable Prometheus output for status assertions.
global.monitoring = [
{
type = "prometheus";
listen = ":9811";
}
];
# Create a periodic snapshot job for an ephemeral zpool.
jobs = [
{
name = "snapshots";
type = "snap";
filesystems."tank/data" = true;
snapshotting = {
type = "periodic";
prefix = "zrepl_";
interval = "10s";
};
pruning.keep = [
{
type = "last_n";
count = 8;
}
];
}
{
name = "backup-target";
type = "source";
serve = {
type = "tcp";
listen = ":8888";
clients = {
"${nodes.target.networking.primaryIPAddress}" = "${nodes.target.networking.hostName}";
"${nodes.target.networking.primaryIPv6Address}" = "${nodes.target.networking.hostName}";
};
};
filesystems."tank/data" = true;
# Snapshots are handled by the separate snap job
snapshotting = {
type = "manual";
};
}
];
};
};
};
};
target =
{ pkgs, ... }:
{
config = {
# Prerequisites for ZFS and tests.
virtualisation.emptyDiskImages = [
2048
];
boot.supportedFilesystems = [ "zfs" ];
environment.systemPackages = [
pkgs.parted
pkgs.zrepl
];
networking.hostId = "deadd0d0";
services.zrepl = {
enable = true;
settings = {
# Enable Prometheus output for status assertions.
global.monitoring = [
{
type = "prometheus";
listen = ":9811";
}
];
jobs = [
{
name = "source-pull";
type = "pull";
connect = {
type = "tcp";
address = "source:8888";
};
root_fs = "tank/zrepl/source";
interval = "15s";
recv = {
placeholder = {
encryption = "off";
};
};
pruning = {
keep_sender = [
{
type = "regex";
regex = ".*";
}
];
keep_receiver = [
{
type = "grid";
grid = "1x1h(keep=all) | 24x1h";
regex = "^zrepl_";
}
];
};
}
];
};
};
};
};
};
testScript = ''
start_all()
with subtest("Wait for zrepl and network ready"):
for machine in source, target:
machine.systemctl("start network-online.target")
machine.wait_for_unit("network-online.target")
machine.wait_for_unit("zrepl.service")
with subtest("Create tank zpool"):
for machine in source, target:
machine.succeed(
"parted --script /dev/vdb mklabel gpt",
"zpool create tank /dev/vdb",
)
# Create ZFS datasets
source.succeed("zfs create tank/data")
target.succeed("zfs create -p tank/zrepl/source")
with subtest("Check for completed zrepl snapshot on target"):
# zrepl periodic snapshot job creates a snapshot with this prefix.
target.wait_until_succeeds("zfs list -t snapshot | grep -q tank/zrepl/source/tank/data@zrepl_")
with subtest("Check for completed zrepl bookmark on source"):
source.wait_until_succeeds("zfs list -t bookmark | grep -q tank/data#zrepl_")
with subtest("Verify HTTP monitoring server is configured"):
out = source.succeed("curl -f localhost:9811/metrics")
assert (
"zrepl_start_time" in out
), "zrepl start time metric was not found in Prometheus output"
assert (
"zrepl_zfs_snapshot_duration_count{filesystem=\"tank/data\"}" in out
), "zrepl snapshot counter for tank/data was not found in Prometheus output"
'';
}
|