zfs_mgmt 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e73c176eec63da1a833242e1f09ee49a9d32b916504a3df52e5c367e00d4478
4
- data.tar.gz: 2e5e6391672e899a6c536bf8cbf0042d5b3102b6e54ccb9da456aeb8f334fb35
3
+ metadata.gz: c44db863ef2ac78801fc53f86a2ab6883f3c73d58b1d9dd7b7a54afd582811e2
4
+ data.tar.gz: 01d7513d55b241eaf74797e64cc2b76a8128444bfdc67403a6a69cb30a994c55
5
5
  SHA512:
6
- metadata.gz: af7bb076d3fd289c1fef89ac9a9727c528e5cfd044548b9d327da9efe68d44713acad4ea052ada422eb117e2fd74767608a56829bf877d544892cb090e10b587
7
- data.tar.gz: b0d56435a2005556e7d28c1f4f9d3752c2c39f6f6b21a39d686902fe8e1198e69aa15850045c20378c5930e4ba17b5bed12a2283e302eecc64d35f13a8979c62
6
+ metadata.gz: 2092a1ec30fb98be06967d544a7ac8aeaad5173ed5eec4a15dd33a23ee79d083f671f9c1df791e3a925fb1bf07d2e33e47d52a4e4de554c958b6fd33493597ac
7
+ data.tar.gz: '079b2834aacb5e44eefd1b71b55f8164f1910ff1394be60a2833a117971c3a138baaadef243315a853855afd910bb2cc49305f664757c6ab017d98a1a08e6787'
data/Gemfile CHANGED
@@ -10,6 +10,8 @@ gem "json"
10
10
  gem "timeout"
11
11
  gem "pstore"
12
12
  gem "easy_talk"
13
+ gem "tomlrb"
14
+ gem "deep_merge"
13
15
 
14
16
  gem 'ruby-lsp', group: :development
15
17
  gemspec
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zfs_mgmt (0.7.3)
4
+ zfs_mgmt (0.8.0)
5
+ deep_merge
5
6
  easy_talk
6
7
  filesize (~> 0.2)
7
8
  pstore
8
9
  text-table (~> 1.2)
9
10
  thor (~> 1.0)
11
+ tomlrb
10
12
 
11
13
  GEM
12
14
  remote: https://rubygems.org/
@@ -31,6 +33,7 @@ GEM
31
33
  character_set (1.9.0)
32
34
  concurrent-ruby (1.3.8)
33
35
  connection_pool (3.0.3)
36
+ deep_merge (1.2.2)
34
37
  diff-lcs (1.6.2)
35
38
  docile (1.4.1)
36
39
  drb (2.2.3)
@@ -89,6 +92,7 @@ GEM
89
92
  text-table (1.2.4)
90
93
  thor (1.5.0)
91
94
  timeout (0.6.1)
95
+ tomlrb (3.0.0)
92
96
  tsort (0.2.0)
93
97
  tzinfo (2.0.6)
94
98
  concurrent-ruby (~> 1.0)
@@ -99,6 +103,7 @@ PLATFORMS
99
103
 
100
104
  DEPENDENCIES
101
105
  bundler (>= 2.2.33)
106
+ deep_merge
102
107
  easy_talk
103
108
  filesize
104
109
  json
@@ -110,6 +115,7 @@ DEPENDENCIES
110
115
  text-table
111
116
  thor
112
117
  timeout
118
+ tomlrb
113
119
  zfs_mgmt!
114
120
 
115
121
  BUNDLED WITH
data/README.md CHANGED
@@ -130,6 +130,57 @@ the `.gem` file to [rubygems.org](https://rubygems.org).
130
130
  Bug reports and pull requests are welcome on GitHub at
131
131
  https://github.com/aranc23/zfs_mgmt.
132
132
 
133
+ ## Configuration File
134
+
135
+ `zfsmgr` loads `*.toml` configuration files from the following directory (unless `--config-dir <path>` is specified):
136
+
137
+ - `/etc/zfsmgr/*.toml` when running as `root`
138
+ - `$XDG_CONFIG_HOME/zfsmgr/*.toml` when non-root and `XDG_CONFIG_HOME` is set
139
+ - `~/.config/zfsmgr/*.toml` when non-root and `XDG_CONFIG_HOME` is unset
140
+
141
+ Files are loaded in lexicographical `sort()` order (for example `00-base.toml` followed by `50-local.toml`) and deep-merged, with later files replacing earlier scalars, arrays, and per-dataset options.
142
+
143
+ Precedence is: **CLI options > per-dataset config (child > parent) > top-level config > ZFS dataset user properties (`zfsmgmt:*`)**.
144
+
145
+ ### Format
146
+
147
+ At the top level, `excludes` and `[overrides]` set default `zfs recv` `-x` and `-o` options. Per-dataset options are configured under `[zfs."pool/dataset"]` using single-bracket TOML tables (not double-bracket `[[zfs."pool/dataset"]]` array-of-tables syntax). Per-dataset `excludes` and `[zfs."pool/dataset".overrides]` are also supported using single-bracket tables. Dataset names containing `/` (or other characters not allowed in TOML bare keys) must be quoted:
148
+
149
+ ```toml
150
+ #:schema https://raw.githubusercontent.com/aranc23/zfs_mgmt/master/schema/config.schema.json
151
+
152
+ excludes = ["mountpoint", "sharenfs"]
153
+
154
+ [overrides]
155
+ canmount = "noauto"
156
+ readonly = "on"
157
+
158
+ [zfs."tank"]
159
+ manage = true
160
+ policy = "10y6m4w30d24h"
161
+ snapshot = true
162
+
163
+ [zfs."tank/data"]
164
+ send = true
165
+ destination = "zfs_recv@backup.example.com:backup/tank"
166
+ excludes = ["quota"]
167
+
168
+ [zfs."tank/data".overrides]
169
+ canmount = "**"
170
+ compression = "zstd"
171
+ ```
172
+
173
+ Dataset options configured in TOML inherit to child datasets (e.g. `tank` -> `tank/data`) with the same source semantics as `zfsmgmt:*` user properties.
174
+
175
+ `destination` in `[zfs."pool/dataset"]` accepts either a single string or an array of strings (for example `destination = ["backup/tank", "zfs_recv@offsite.example.com:offsite/tank"]`) to send a dataset to multiple destinations.
176
+
177
+ Unlike scalar options (where a higher-precedence source replaces lower ones), `excludes` and `overrides` are **merged** from lowest precedence (`zfsmgmt:excludes` / `zfsmgmt:overrides`) up through top-level config, per-dataset config (ancestor to child), and CLI `--exclude` / `--option` flags. To unset a value set at a lower precedence level, use the `**` knockout prefix:
178
+ - In `overrides`: set `prop = "**"` in TOML (or `prop=**` / `**prop` on the CLI or `zfsmgmt:overrides`) to remove `prop` from lower levels, or `"**"` alone to clear all lower-level overrides.
179
+ - In `excludes`: include `"**prop"` to remove `prop` from lower levels, or `"**"` to clear all lower-level excludes.
180
+ - A higher-precedence layer can re-add an exclude or override that was knocked out at an intermediate layer.
181
+
182
+ See [examples/config.toml](examples/config.toml) for a full example and [schema/config.schema.json](schema/config.schema.json) for the JSON Schema (used by TOML editors/validators via the `#:schema` directive; regenerate with `bundle exec rake schema`).
183
+
133
184
  ## zfs user properties
134
185
 
135
186
  Destruction of zfs snapshots is based on the following zfs user
@@ -228,14 +279,28 @@ or `'local'`:
228
279
  - `local`: enables `zfs send` only when the property's ZFS source is
229
280
  `local` (not inherited or received).
230
281
 
231
- ### zfsmgmt:remote
232
- Remote SSH target for `zfs recv` and remote `zfs get` checks (e.g.
233
- `user@host`). When omitted, `zfs recv` runs locally.
282
+ ### zfsmgmt:remote *(deprecated)*
283
+ Deprecated. Remote SSH target for `zfs recv` and remote `zfs get` checks
284
+ (e.g. `user@host`). Specify the remote host directly in `zfsmgmt:destination`
285
+ instead (e.g. `user@host:backup/tank`). When set, logs a deprecation warning
286
+ and prepends the remote host to `destination` only if `destination` does not
287
+ already include a `hostname:` or `user@hostname:` prefix.
234
288
 
235
289
  ### zfsmgmt:destination
236
- Base destination ZFS dataset path for `zfs send`/`recv` (required for
237
- `zfsmgr send all`, even if `--destination` is passed on the command
238
- line):
290
+ Base destination ZFS dataset path(s) for `zfs send`/`recv` (required for
291
+ `zfsmgr send all`). Supports local and remote forms:
292
+ - `zpool/zfs/zfs2` (local)
293
+ - `hostname:zpool/zfs/zfs2` (remote via SSH)
294
+ - `user@hostname:zpool/zfs/zfs2` (remote via SSH with user)
295
+
296
+ Multiple destinations can be configured as a comma-separated list in the
297
+ `zfsmgmt:destination` user property (for example
298
+ `host1:backup/tank,backup2/tank`) or as a TOML array in `[zfs."<dataset>"]`
299
+ (`destination = ["host1:backup/tank", "backup2/tank"]`). Each destination
300
+ is sent independently and tracked separately by `(source, destination)` in
301
+ the send state database.
302
+
303
+ Path resolution rules:
239
304
  - When the property's ZFS source is `local`, the destination path
240
305
  resolves to `<destination>/<dataset basename>`.
241
306
  - When the property's ZFS source is `inherited from <ancestor>`, the
@@ -244,32 +309,25 @@ line):
244
309
  - When the source is `received` (or unrecognized), no destination is
245
310
  resolved.
246
311
 
247
- ### zfsmgmt:send_intermediary (default: false)
248
- Boolean (`true`/`on`). Pass `-I` (include intermediary snapshots) to
249
- `zfs send`.
250
-
251
- ### zfsmgmt:send_backup (default: false)
252
- Boolean (`true`/`on`). Pass `-b` (send received property values) to
253
- `zfs send`.
254
-
255
- ### zfsmgmt:send_compressed (default: false)
256
- Boolean (`true`/`on`). Pass `-c` (send compressed blocks) to `zfs send`.
257
-
258
- ### zfsmgmt:send_embed (default: false)
259
- Boolean (`true`/`on`). Pass `-e` (send embedded data) to `zfs send`.
260
-
261
- ### zfsmgmt:send_holds (default: false)
262
- Boolean (`true`/`on`). Pass `-h` (send snapshot holds) to `zfs send`.
263
-
264
- ### zfsmgmt:send_large_block (default: false)
265
- Boolean (`true`/`on`). Pass `-L` (allow large blocks) to `zfs send`.
266
-
267
- ### zfsmgmt:send_props (default: false)
268
- Boolean (`true`/`on`). Pass `-p` (send properties) to `zfs send`.
269
-
270
- ### zfsmgmt:send_raw (default: false)
271
- Boolean (`true`/`on`). Pass `-w` (send raw encrypted stream) to
272
- `zfs send`.
312
+ ### zfs send / recv flags
313
+
314
+ The following boolean options (`true`/`on`, or `false`/`off` in ZFS user properties; `true`/`false` in `[zfs."<dataset>"]` TOML config) map directly to `zfs send` or `zfs recv` command-line flags and can be overridden via `zfsmgr send all` CLI flags:
315
+
316
+ | User Property | Config Key | ZFS Option | Default | Description |
317
+ | --- | --- | --- | --- | --- |
318
+ | `zfsmgmt:send_intermediary` | `send_intermediary` | `zfs send -I` | `false` | Include intermediary snapshots |
319
+ | `zfsmgmt:send_backup` | `send_backup` | `zfs send -b` | `false` | Send received property values |
320
+ | `zfsmgmt:send_compressed` | `send_compressed` | `zfs send -c` | `false` | Send compressed blocks |
321
+ | `zfsmgmt:send_embed` | `send_embed` | `zfs send -e` | `false` | Send embedded data |
322
+ | `zfsmgmt:send_holds` | `send_holds` | `zfs send -h` | `false` | Send snapshot holds |
323
+ | `zfsmgmt:send_large_block` | `send_large_block` | `zfs send -L` | `false` | Allow large blocks |
324
+ | `zfsmgmt:send_props` | `send_props` | `zfs send -p` | `false` | Send properties |
325
+ | `zfsmgmt:send_raw` | `send_raw` | `zfs send -w` | `false` | Send raw encrypted stream |
326
+ | `zfsmgmt:recv_state` | `recv_state` | `zfs recv -s` | `true` | Save partial receive state for resuming |
327
+ | `zfsmgmt:recv_noop` | `recv_noop` | `zfs recv -n` | `false` | Dry-run (do not actually receive) |
328
+ | `zfsmgmt:recv_drop_holds` | `recv_drop_holds` | `zfs recv -h` | `false` | Skip receiving holds |
329
+ | `zfsmgmt:recv_unmount` | `recv_unmount` | `zfs recv -u` | `false` | Do not mount received filesystem |
330
+ | `zfsmgmt:recv_force` | `recv_force` | `zfs recv -F` | `false` | Force rollback |
273
331
 
274
332
  ### zfsmgmt:send_replicate (default: false)
275
333
  Boolean (`true`/`on`). Pass `-R` (replication stream) to `zfs send` and
@@ -278,30 +336,25 @@ dataset where `zfsmgmt:send_replicate` is `local`; descendant datasets
278
336
  inheriting it have both `send` and `send_replicate` disabled so they are
279
337
  not sent separately.
280
338
 
281
- ### zfsmgmt:recv_state (default: true)
282
- Boolean. Pass `-s` (save partial receive state for resuming) to
283
- `zfs recv`. Enabled by default unless set to `false` or `off` (or
284
- overridden on the CLI).
285
-
286
- ### zfsmgmt:recv_noop (default: false)
287
- Boolean (`true`/`on`). Pass `-n` (dry-run / do not actually receive) to
288
- `zfs recv`.
289
-
290
- ### zfsmgmt:recv_drop_holds (default: false)
291
- Boolean (`true`/`on`). Pass `-h` (skip receiving holds) to `zfs recv`.
292
-
293
- ### zfsmgmt:recv_unmount (default: false)
294
- Boolean (`true`/`on`). Pass `-u` (do not mount received filesystem) to
295
- `zfs recv`.
296
-
297
339
  ### zfsmgmt:recv_discard_first (default: false)
298
340
  Boolean (`true`/`on`). Pass `-d` (discard the first element of the sent
299
341
  snapshot's filesystem name) to `zfs recv`, passing the base
300
- `zfsmgmt:destination` (or `--destination`) as the `zfs recv` target and
342
+ `zfsmgmt:destination` as the `zfs recv` target and
301
343
  stripping the first path element for remote existence/snapshot checks.
302
344
 
303
- ### zfsmgmt:recv_force (default: false)
304
- Boolean (`true`/`on`). Pass `-F` (force rollback) to `zfs recv`.
345
+ ### zfsmgmt:excludes
346
+ Comma-separated list of ZFS properties to exclude on `zfs recv` (`-x`),
347
+ for example `mountpoint,sharenfs`. Merged with top-level config,
348
+ per-dataset config, and CLI `--exclude` (`-x`) options. Prefix a
349
+ property with `**` (e.g. `**mountpoint`) to knock out an excluded
350
+ property, or use `**` to clear lower-precedence excludes.
351
+
352
+ ### zfsmgmt:overrides
353
+ Comma-separated list of `property=value` overrides to pass to `zfs recv`
354
+ (`-o`), for example `canmount=noauto,readonly=on`. Merged with top-level
355
+ config, per-dataset config, and CLI `--option` (`-o`) options. Use
356
+ `property=**` (or `**property`) to knock out an override, or `**` to
357
+ clear lower-precedence overrides.
305
358
 
306
359
  ### zfsmgmt:restic_backup
307
360
  boolean, send this zfs to restic
data/Rakefile CHANGED
@@ -3,4 +3,22 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
+ namespace :schema do
7
+ desc "Generate JSON Schema for zfsmgr config files (default: schema/config.schema.json)"
8
+ task :generate, [:output] do |_t, args|
9
+ $LOAD_PATH.unshift(File.expand_path("lib", __dir__))
10
+ require "json"
11
+ require "fileutils"
12
+ require "zfs_mgmt"
13
+
14
+ output = args[:output] || File.expand_path("schema/config.schema.json", __dir__)
15
+ FileUtils.mkdir_p(File.dirname(output))
16
+ File.write(output, JSON.pretty_generate(ZfsMgmt::Config.config_json_schema) + "\n")
17
+ puts "Wrote JSON schema to #{output}"
18
+ end
19
+ end
20
+
21
+ desc "Generate JSON Schema for zfsmgr config files"
22
+ task :schema => "schema:generate"
23
+
6
24
  task :default => :spec
data/bin/zfsmgr CHANGED
@@ -24,12 +24,15 @@ class ZfsMgr < Thor
24
24
  :desc => 'lock file'
25
25
  class_option :lock_wait, :type => :numeric, :default => 0,
26
26
  :desc => 'wait N seconds for lock'
27
+ class_option :config_dir, :type => :string,
28
+ :desc => 'directory containing zfsmgr .toml config files'
27
29
  desc "zfsget [ZFS]", "execute zfs get for the given properties and types and parse the output into a nested hash"
28
30
  method_option :properties, :type => :string, :default => ['name'], :desc => "List of properties passed to zfs get", repeatable: true
29
31
  method_option :types, :type => :array, :default => ['filesystem','volume'], enum: ['filesystem','volume','snapshot'], :desc => "list of types"
30
32
  def zfsget(zfs)
31
33
  ZfsMgmt.set_log_level(options[:loglevel])
32
34
  ZfsMgmt.global_options = options
35
+ ZfsMgmt.load_config
33
36
  pp ZfsMgmt.zfsget(properties: options[:properties],
34
37
  types: options[:types],
35
38
  zfs: zfs)
@@ -0,0 +1,105 @@
1
+ #:schema https://raw.githubusercontent.com/aranc23/zfs_mgmt/master/schema/config.schema.json
2
+ #
3
+ # Sample configuration for zfsmgr
4
+ #
5
+ # Editors and validators such as Taplo (VS Code "Even Better TOML", Neovim taplo)
6
+ # use the #:schema directive above to validate against the raw GitHub URL
7
+ # (you can also pin it to a tagged release URL or a local file path).
8
+ #
9
+ # Configuration files are loaded from *.toml in:
10
+ # - /etc/zfsmgr/*.toml (when running as root)
11
+ # - $XDG_CONFIG_HOME/zfsmgr/*.toml (when non-root and XDG_CONFIG_HOME is set)
12
+ # - ~/.config/zfsmgr/*.toml (when non-root and XDG_CONFIG_HOME is unset)
13
+ # - --config-dir <path> (CLI override)
14
+ #
15
+ # Multiple *.toml files in the directory are loaded in lexicographical sort() order
16
+ # (e.g. 00-base.toml then 50-local.toml) and deep-merged, with later files replacing
17
+ # earlier scalars, arrays, and dataset keys.
18
+ #
19
+ # Precedence: CLI options > per-dataset config (child > parent) > top-level config > ZFS dataset user properties (zfsmgmt:*).
20
+ # Dataset options configured here also inherit to child datasets (e.g. tank -> tank/data)
21
+ # with the same source semantics as ZFS user properties.
22
+ #
23
+ # excludes and overrides are merged across precedence layers (lowest to highest).
24
+ # Use the "**" knockout prefix to unset a value from a lower precedence layer:
25
+ # - in excludes: "**mountpoint" removes "mountpoint"; "**" clears all lower excludes
26
+ # - in overrides: canmount = "**" removes "canmount"; "**" clears all lower overrides
27
+
28
+ # ---------------------------------------------------------------------------
29
+ # Top-level zfs recv options (previously only available via CLI flags)
30
+ # ---------------------------------------------------------------------------
31
+
32
+ # Properties to exclude on zfs recv (-x <property>).
33
+ # Note: volume-unsupported properties (canmount, mountpoint, quota) are
34
+ # automatically omitted when receiving ZFS volumes.
35
+ excludes = [
36
+ "mountpoint",
37
+ "sharenfs",
38
+ "sharesmb",
39
+ ]
40
+
41
+ # Property overrides to set on zfs recv (-o <property>=<value>).
42
+ # Note: volume-unsupported properties (canmount, mountpoint, quota) are
43
+ # automatically omitted when receiving ZFS volumes.
44
+ [overrides]
45
+ canmount = "noauto"
46
+ readonly = "on"
47
+
48
+ # ---------------------------------------------------------------------------
49
+ # Per-dataset options (mirroring zfsmgmt:* user properties)
50
+ # Each dataset is configured as a standard TOML table: [zfs."pool/dataset"]
51
+ # (not an array-of-tables [[zfs."pool/dataset"]]). Dataset names containing
52
+ # '/' (or other non-bare-key characters) must be quoted.
53
+ # ---------------------------------------------------------------------------
54
+
55
+ # Parent dataset: snapshot retention & creation defaults inherited by children
56
+ [zfs."tank"]
57
+ manage = true
58
+ policy = "10y6m4w30d24h"
59
+ strategy = "oldest" # "oldest" (default) or "youngest"
60
+ minage = "7d" # s, m, h, d, w (or unitless seconds)
61
+ matchsnaps = "^zfsmgmt-" # regexp snapshot name must match to satisfy policy
62
+ ignoresnaps = "^syncoid_" # regexp snapshot name to ignore for policy & destroy
63
+ prefersnaps = "^daily-" # regexp snapshot name preferred when retaining
64
+ snapshot = true # true, false, "recursive", or "local"
65
+ snap_prefix = "zfsmgmt"
66
+ snap_timestamp = "%FT%T%z"
67
+
68
+ # Child dataset: inherits tank's snapshot policy, configures zfs send/recv
69
+ [zfs."tank/data"]
70
+ send = true # true, false, or "local" (only send this dataset)
71
+ destination = "zfs_recv@backup.example.com:backup/tank"
72
+
73
+ # zfs send flags
74
+ send_intermediary = true # -I
75
+ send_backup = false # -b
76
+ send_compressed = true # -c
77
+ send_embed = false # -e
78
+ send_holds = true # -h
79
+ send_large_block = false # -L
80
+ send_props = true # -p
81
+ send_raw = true # -w
82
+ send_replicate = false # -R (only applies on dataset where set locally)
83
+
84
+ # zfs recv flags
85
+ recv_state = true # -s (defaults to true unless set to false)
86
+ recv_noop = false # -n
87
+ recv_drop_holds = false # -h
88
+ recv_unmount = true # -u
89
+ recv_discard_first = false # -d (uses base destination as target)
90
+ recv_force = false # -F
91
+ excludes = ["quota"] # merged with top-level excludes and zfsmgmt:excludes
92
+
93
+ # Per-dataset zfs recv property overrides (merged with top-level [overrides] and zfsmgmt:overrides)
94
+ [zfs."tank/data".overrides]
95
+ canmount = "**" # knock out top-level canmount = "noauto"
96
+ compression = "zstd"
97
+
98
+ # Child dataset with local overrides, multiple send destinations, and restic backup settings
99
+ [zfs."tank/archive"]
100
+ manage = false
101
+ snapshot = "recursive"
102
+ send = "local"
103
+ destination = ["backup/archive", "zfs_recv@offsite.example.com:offsite/archive"]
104
+ restic_backup = true
105
+ restic_repository = "/srv/restic/zfs"