zfs_mgmt 0.6.1 → 0.7.3
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 +4 -4
- data/AGENTS.md +1 -0
- data/Gemfile.lock +4 -4
- data/README.md +84 -0
- data/bin/zfsmgr +6 -0
- data/lib/zfs_mgmt/version.rb +1 -1
- data/lib/zfs_mgmt/zfs.rb +49 -3
- data/lib/zfs_mgmt/zfs_mgr/send.rb +0 -1
- data/lib/zfs_mgmt.rb +38 -13
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e73c176eec63da1a833242e1f09ee49a9d32b916504a3df52e5c367e00d4478
|
|
4
|
+
data.tar.gz: 2e5e6391672e899a6c536bf8cbf0042d5b3102b6e54ccb9da456aeb8f334fb35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: af7bb076d3fd289c1fef89ac9a9727c528e5cfd044548b9d327da9efe68d44713acad4ea052ada422eb117e2fd74767608a56829bf877d544892cb090e10b587
|
|
7
|
+
data.tar.gz: b0d56435a2005556e7d28c1f4f9d3752c2c39f6f6b21a39d686902fe8e1198e69aa15850045c20378c5930e4ba17b5bed12a2283e302eecc64d35f13a8979c62
|
data/AGENTS.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
zfs_mgmt (0.
|
|
4
|
+
zfs_mgmt (0.7.3)
|
|
5
5
|
easy_talk
|
|
6
6
|
filesize (~> 0.2)
|
|
7
7
|
pstore
|
|
@@ -46,14 +46,14 @@ GEM
|
|
|
46
46
|
character_set (~> 1.4)
|
|
47
47
|
regexp_parser (~> 2.11)
|
|
48
48
|
regexp_property_values (~> 1.0)
|
|
49
|
-
json (3.
|
|
49
|
+
json (3.2.0)
|
|
50
50
|
language_server-protocol (3.17.0.6)
|
|
51
51
|
logger (1.7.0)
|
|
52
52
|
minitest (6.1.0)
|
|
53
53
|
drb (~> 2.0)
|
|
54
54
|
prism (>= 1.5, < 3)
|
|
55
55
|
prism (1.9.0)
|
|
56
|
-
pstore (0.
|
|
56
|
+
pstore (0.3.0)
|
|
57
57
|
rake (13.4.2)
|
|
58
58
|
rbs (4.2.0)
|
|
59
59
|
logger
|
|
@@ -85,7 +85,7 @@ GEM
|
|
|
85
85
|
simplecov_json_formatter (~> 0.1)
|
|
86
86
|
simplecov-html (0.13.2)
|
|
87
87
|
simplecov_json_formatter (0.1.4)
|
|
88
|
-
sorbet-runtime (0.6.
|
|
88
|
+
sorbet-runtime (0.6.13724)
|
|
89
89
|
text-table (1.2.4)
|
|
90
90
|
thor (1.5.0)
|
|
91
91
|
timeout (0.6.1)
|
data/README.md
CHANGED
|
@@ -219,6 +219,90 @@ create snapshots called autosnap-%FT%T%z.
|
|
|
219
219
|
strftime format string used when creating snapshot names, default
|
|
220
220
|
being %FT%T%z.
|
|
221
221
|
|
|
222
|
+
### zfsmgmt:send
|
|
223
|
+
Enable `zfs send` for this dataset. Accepts boolean values (`true`/`on`)
|
|
224
|
+
or `'local'`:
|
|
225
|
+
- `true` or `on`: enables `zfs send` when the property's ZFS source is
|
|
226
|
+
`local` or `inherited`, and disables it when the source is `received`
|
|
227
|
+
or when `zfsmgmt:send_replicate` is inherited from an ancestor.
|
|
228
|
+
- `local`: enables `zfs send` only when the property's ZFS source is
|
|
229
|
+
`local` (not inherited or received).
|
|
230
|
+
|
|
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.
|
|
234
|
+
|
|
235
|
+
### 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):
|
|
239
|
+
- When the property's ZFS source is `local`, the destination path
|
|
240
|
+
resolves to `<destination>/<dataset basename>`.
|
|
241
|
+
- When the property's ZFS source is `inherited from <ancestor>`, the
|
|
242
|
+
destination path resolves to
|
|
243
|
+
`<destination>/<ancestor basename>/<relative path>`.
|
|
244
|
+
- When the source is `received` (or unrecognized), no destination is
|
|
245
|
+
resolved.
|
|
246
|
+
|
|
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`.
|
|
273
|
+
|
|
274
|
+
### zfsmgmt:send_replicate (default: false)
|
|
275
|
+
Boolean (`true`/`on`). Pass `-R` (replication stream) to `zfs send` and
|
|
276
|
+
use the newest snapshot for initial send. Only takes effect on the
|
|
277
|
+
dataset where `zfsmgmt:send_replicate` is `local`; descendant datasets
|
|
278
|
+
inheriting it have both `send` and `send_replicate` disabled so they are
|
|
279
|
+
not sent separately.
|
|
280
|
+
|
|
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
|
+
### zfsmgmt:recv_discard_first (default: false)
|
|
298
|
+
Boolean (`true`/`on`). Pass `-d` (discard the first element of the sent
|
|
299
|
+
snapshot's filesystem name) to `zfs recv`, passing the base
|
|
300
|
+
`zfsmgmt:destination` (or `--destination`) as the `zfs recv` target and
|
|
301
|
+
stripping the first path element for remote existence/snapshot checks.
|
|
302
|
+
|
|
303
|
+
### zfsmgmt:recv_force (default: false)
|
|
304
|
+
Boolean (`true`/`on`). Pass `-F` (force rollback) to `zfs recv`.
|
|
305
|
+
|
|
222
306
|
### zfsmgmt:restic_backup
|
|
223
307
|
boolean, send this zfs to restic
|
|
224
308
|
|
data/bin/zfsmgr
CHANGED
|
@@ -42,6 +42,12 @@ class ZfsMgr < Thor
|
|
|
42
42
|
subcommand "restic", ZfsMgmt::ZfsMgr::Restic
|
|
43
43
|
desc "send SUBCOMMAND ...ARGS", "send zfs"
|
|
44
44
|
subcommand "send", ZfsMgmt::ZfsMgr::Send
|
|
45
|
+
|
|
46
|
+
map '--version' => :version
|
|
47
|
+
desc "version", "print zfs_mgmt version"
|
|
48
|
+
def version
|
|
49
|
+
puts "zfsmgr #{ZfsMgmt::VERSION}"
|
|
50
|
+
end
|
|
45
51
|
end
|
|
46
52
|
|
|
47
53
|
ZfsMgr.start(ARGV)
|
data/lib/zfs_mgmt/version.rb
CHANGED
data/lib/zfs_mgmt/zfs.rb
CHANGED
|
@@ -20,17 +20,30 @@ module ZfsMgmt
|
|
|
20
20
|
recv_noop
|
|
21
21
|
recv_drop_holds
|
|
22
22
|
recv_unmount
|
|
23
|
-
recv_discard_last
|
|
24
23
|
recv_discard_first
|
|
25
24
|
recv_force
|
|
26
25
|
].freeze
|
|
27
26
|
|
|
27
|
+
VALID_ZFS_PROPS = (
|
|
28
|
+
%w[
|
|
29
|
+
manage policy strategy minage matchsnaps ignoresnaps prefersnaps
|
|
30
|
+
snapshot snap_prefix snap_timestamp
|
|
31
|
+
send remote destination send_replicate
|
|
32
|
+
recv_state
|
|
33
|
+
restic_backup restic_repository
|
|
34
|
+
] +
|
|
35
|
+
SEND_BOOL_PROPS.map(&:to_s) +
|
|
36
|
+
RECV_BOOL_PROPS.map(&:to_s)
|
|
37
|
+
).map { |p| "zfsmgmt:#{p}" }.freeze
|
|
38
|
+
|
|
28
39
|
define_schema do
|
|
29
40
|
title 'Zfs'
|
|
30
41
|
description 'Encapsulates zfsmgmt:* user properties for a ZFS dataset'
|
|
31
42
|
|
|
32
43
|
property :name, String,
|
|
33
44
|
description: 'Full name of the ZFS dataset (e.g. tank/data)'
|
|
45
|
+
property :type, String, optional: true, enum: %w[filesystem volume],
|
|
46
|
+
description: 'ZFS dataset type (filesystem or volume)'
|
|
34
47
|
|
|
35
48
|
# Snapshot retention policy properties
|
|
36
49
|
property :manage, T::Boolean, optional: true, default: false,
|
|
@@ -93,8 +106,6 @@ module ZfsMgmt
|
|
|
93
106
|
description: 'Pass -h (drop holds) to zfs recv'
|
|
94
107
|
property :recv_unmount, T::Boolean, optional: true, default: false,
|
|
95
108
|
description: 'Pass -u (unmount) to zfs recv'
|
|
96
|
-
property :recv_discard_last, T::Boolean, optional: true, default: false,
|
|
97
|
-
description: 'Pass -e (discard all but last path element) to zfs recv'
|
|
98
109
|
property :recv_discard_first, T::Boolean, optional: true, default: false,
|
|
99
110
|
description: 'Pass -d (discard first path element) to zfs recv'
|
|
100
111
|
property :recv_force, T::Boolean, optional: true, default: false,
|
|
@@ -111,6 +122,7 @@ module ZfsMgmt
|
|
|
111
122
|
attrs = attributes.transform_keys(&:to_sym)
|
|
112
123
|
@snapshots = attrs.delete(:snapshots) if attrs.key?(:snapshots)
|
|
113
124
|
@destination_relative_path = attrs.delete(:destination_relative_path) if attrs.key?(:destination_relative_path)
|
|
125
|
+
@destination_base = attrs.delete(:destination_base) if attrs.key?(:destination_base)
|
|
114
126
|
if attrs.key?(:send) && !attrs.key?(:send_enabled)
|
|
115
127
|
attrs[:send_enabled] = attrs.delete(:send)
|
|
116
128
|
end
|
|
@@ -125,6 +137,10 @@ module ZfsMgmt
|
|
|
125
137
|
send_enabled == true
|
|
126
138
|
end
|
|
127
139
|
|
|
140
|
+
def volume?
|
|
141
|
+
type == 'volume'
|
|
142
|
+
end
|
|
143
|
+
|
|
128
144
|
def snapshots
|
|
129
145
|
return @snapshots unless @snapshots.nil?
|
|
130
146
|
|
|
@@ -155,9 +171,37 @@ module ZfsMgmt
|
|
|
155
171
|
File.join(override, rel)
|
|
156
172
|
end
|
|
157
173
|
|
|
174
|
+
def base_destination(override = nil)
|
|
175
|
+
return override if override
|
|
176
|
+
|
|
177
|
+
@destination_base || destination
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def discard_first_destination(override = nil)
|
|
181
|
+
base = base_destination(override)
|
|
182
|
+
return nil unless base
|
|
183
|
+
|
|
184
|
+
rel = name.include?('/') ? name.split('/', 2).last : nil
|
|
185
|
+
rel && !rel.empty? ? File.join(base, rel) : base
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def self.warn_unknown_zfs_props(name, props)
|
|
189
|
+
props.each_key do |key|
|
|
190
|
+
key_str = key.to_s
|
|
191
|
+
next unless key_str.start_with?('zfsmgmt:')
|
|
192
|
+
next if key_str.end_with?('@source')
|
|
193
|
+
next if VALID_ZFS_PROPS.include?(key_str)
|
|
194
|
+
|
|
195
|
+
target = name.nil? || name.empty? ? '' : " on #{name}"
|
|
196
|
+
$logger&.warn("unknown zfsmgmt property '#{key_str}'#{target}")
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
158
200
|
def self.from_zfs_props(name, props = {})
|
|
159
201
|
props ||= {}
|
|
202
|
+
warn_unknown_zfs_props(name, props)
|
|
160
203
|
attrs = { name: name }
|
|
204
|
+
attrs[:type] = props['type'] if props.key?('type')
|
|
161
205
|
|
|
162
206
|
attrs[:manage] = ZfsMgmt.prop_on?(props['zfsmgmt:manage'])
|
|
163
207
|
attrs[:policy] = props['zfsmgmt:policy'] if props.key?('zfsmgmt:policy')
|
|
@@ -214,10 +258,12 @@ module ZfsMgmt
|
|
|
214
258
|
rel = File.basename(name)
|
|
215
259
|
attrs[:destination] = File.join(dest_base, rel)
|
|
216
260
|
attrs[:destination_relative_path] = rel
|
|
261
|
+
attrs[:destination_base] = dest_base
|
|
217
262
|
elsif dest_src && (m = /\Ainherited from (.+)\z/.match(dest_src))
|
|
218
263
|
rel = File.join(File.basename(m[1]), name.sub(m[1], ''))
|
|
219
264
|
attrs[:destination] = File.join(dest_base, rel)
|
|
220
265
|
attrs[:destination_relative_path] = rel
|
|
266
|
+
attrs[:destination_base] = dest_base
|
|
221
267
|
end
|
|
222
268
|
end
|
|
223
269
|
|
|
@@ -29,7 +29,6 @@ class ZfsMgmt::ZfsMgr::Send < Thor
|
|
|
29
29
|
method_option :exclude, :aliases => :'-x', :desc => "passed to -x option of receive side", :type => :string, repeatable: true
|
|
30
30
|
method_option :option, :aliases => :'-o', :desc => "passed to -o option of receive side", :type => :string, repeatable: true
|
|
31
31
|
method_option :drop_holds, :desc => "pass the -h option to zfs recv, indicating holds should be ignored", :type => :boolean
|
|
32
|
-
method_option :discard_last, :desc => "pass the -e option to zfs recv, discarding all but the last element of the send snapshot's file system name", :type => :boolean
|
|
33
32
|
method_option :discard_first, :desc => "pass the -d option to zfs recv, discarding the first element of the send snapshot's file system name", :type => :boolean
|
|
34
33
|
method_option :recv_state, :aliases => :'-s', :desc => "pass the -s option to zfs recv to save partial receive state for resuming (defaults to true unless disabled)", :type => :boolean
|
|
35
34
|
|
data/lib/zfs_mgmt.rb
CHANGED
|
@@ -421,7 +421,13 @@ module ZfsMgmt
|
|
|
421
421
|
end
|
|
422
422
|
zfs_name = zfs_obj.name
|
|
423
423
|
sorted = snaps.keys.sort { |a,b| snaps[a]['creation'] <=> snaps[b]['creation'] }
|
|
424
|
-
|
|
424
|
+
discard_first = recv_discard_first?(options, zfs_obj)
|
|
425
|
+
destination_path = if discard_first
|
|
426
|
+
zfs_obj.discard_first_destination(options[:destination])
|
|
427
|
+
else
|
|
428
|
+
zfs_obj.resolved_destination(options[:destination])
|
|
429
|
+
end
|
|
430
|
+
recv_target = discard_first ? zfs_obj.base_destination(options[:destination]) : destination_path
|
|
425
431
|
unless destination_path
|
|
426
432
|
$logger.error("fatal error: unable to determine destination path for #{zfs_name}")
|
|
427
433
|
exit(1)
|
|
@@ -464,7 +470,7 @@ module ZfsMgmt
|
|
|
464
470
|
e = zfs_send_estimate(com) if options[:verbose] == 'pv'
|
|
465
471
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
466
472
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
467
|
-
com += zfs_recv_com(options,[],zfs_obj,
|
|
473
|
+
com += zfs_recv_com(options,[],zfs_obj,recv_target)
|
|
468
474
|
|
|
469
475
|
status = system_com(com)
|
|
470
476
|
record_send_state(zfs_name, status) unless options[:noop]
|
|
@@ -482,7 +488,7 @@ module ZfsMgmt
|
|
|
482
488
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
483
489
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
484
490
|
|
|
485
|
-
com += zfs_recv_com(options,[],zfs_obj,
|
|
491
|
+
com += zfs_recv_com(options,[],zfs_obj,recv_target)
|
|
486
492
|
|
|
487
493
|
status = system_com(com)
|
|
488
494
|
record_send_state(zfs_name, status) unless options[:noop]
|
|
@@ -527,7 +533,7 @@ module ZfsMgmt
|
|
|
527
533
|
e = zfs_send_estimate(com) if options[:verbose] == 'pv'
|
|
528
534
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
529
535
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
530
|
-
com += zfs_recv_com(options,[],zfs_obj,
|
|
536
|
+
com += zfs_recv_com(options,[],zfs_obj,recv_target)
|
|
531
537
|
|
|
532
538
|
status = system_com(com)
|
|
533
539
|
record_send_state(zfs_name, status) unless options[:noop]
|
|
@@ -580,6 +586,24 @@ module ZfsMgmt
|
|
|
580
586
|
return false if key_comp?(props, 'zfsmgmt:recv_state', method(:prop_off?))
|
|
581
587
|
true
|
|
582
588
|
end
|
|
589
|
+
def self.recv_discard_first?(options, zfs_obj)
|
|
590
|
+
if key_comp?(options, 'discard_first', [true, false])
|
|
591
|
+
key_comp?(options, 'discard_first', true)
|
|
592
|
+
else
|
|
593
|
+
zfs_obj.recv_discard_first
|
|
594
|
+
end
|
|
595
|
+
end
|
|
596
|
+
VOLUME_UNSUPPORTED_RECV_PROPERTIES = %w[
|
|
597
|
+
canmount
|
|
598
|
+
mountpoint
|
|
599
|
+
quota
|
|
600
|
+
].freeze
|
|
601
|
+
|
|
602
|
+
def self.unsupported_volume_recv_prop?(prop_spec)
|
|
603
|
+
prop_name = prop_spec.to_s.split('=', 2).first.to_s.strip.downcase
|
|
604
|
+
VOLUME_UNSUPPORTED_RECV_PROPERTIES.include?(prop_name)
|
|
605
|
+
end
|
|
606
|
+
|
|
583
607
|
def self.zfs_recv_com(options,extra_opts,props,target)
|
|
584
608
|
zfs_obj = props.is_a?(ZfsMgmt::Zfs) ? props : ZfsMgmt::Zfs.from_zfs_props('', props)
|
|
585
609
|
zfs_recv_com = [ ZfsMgmt.global_options[:zfs_binary], 'recv' ]
|
|
@@ -588,7 +612,6 @@ module ZfsMgmt
|
|
|
588
612
|
'noop' => '-n',
|
|
589
613
|
'drop_holds' => '-h',
|
|
590
614
|
'unmount' => '-u',
|
|
591
|
-
'discard_last' => '-e',
|
|
592
615
|
'discard_first' => '-d',
|
|
593
616
|
'force' => '-F'
|
|
594
617
|
}
|
|
@@ -601,14 +624,16 @@ module ZfsMgmt
|
|
|
601
624
|
end
|
|
602
625
|
end
|
|
603
626
|
zfs_recv_com.push('-v') if key_comp?(options, 'verbose', ['receive', 'recv'])
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
627
|
+
volume = zfs_obj.volume?
|
|
628
|
+
[['-x', options[:exclude]], ['-o', options[:option]]].each do |flag, values|
|
|
629
|
+
next unless values
|
|
630
|
+
|
|
631
|
+
values.each do |val|
|
|
632
|
+
if volume && unsupported_volume_recv_prop?(val)
|
|
633
|
+
$logger.debug("skipping #{flag} #{val} for volume #{zfs_obj.name}")
|
|
634
|
+
next
|
|
635
|
+
end
|
|
636
|
+
zfs_recv_com.push(flag, val)
|
|
612
637
|
end
|
|
613
638
|
end
|
|
614
639
|
zfs_recv_com += extra_opts
|