zfs_mgmt 0.6.1 → 0.7.2
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 +1 -1
- data/bin/zfsmgr +6 -0
- data/lib/zfs_mgmt/version.rb +1 -1
- data/lib/zfs_mgmt/zfs.rb +24 -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: a8a0a54f571a60983fafec4ad7271ef0cc4faef234dccefd91e4631e6eea215d
|
|
4
|
+
data.tar.gz: b0fbde6ff8a63cb12af2152055994d939c32b2bc8d5a16709c0d490d6839f640
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3ed57c967167273677681a56ef4f88230e36cea2c4308a6f3335855261c2eb9d88a0b13fa1ee532e4952baccd9af4dee72828c1be93bede1a5f1559a4e2586c
|
|
7
|
+
data.tar.gz: 3502e04546f683750f450b27f85aae186f8d425b730ed530c2df4171fde3de1781a9bc40e4c07b38503ac1d14d242d757163abbeaf0a2fcdd4451c56d2a62e03
|
data/AGENTS.md
CHANGED
data/Gemfile.lock
CHANGED
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,7 +20,6 @@ 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
|
|
@@ -31,6 +30,8 @@ module ZfsMgmt
|
|
|
31
30
|
|
|
32
31
|
property :name, String,
|
|
33
32
|
description: 'Full name of the ZFS dataset (e.g. tank/data)'
|
|
33
|
+
property :type, String, optional: true, enum: %w[filesystem volume],
|
|
34
|
+
description: 'ZFS dataset type (filesystem or volume)'
|
|
34
35
|
|
|
35
36
|
# Snapshot retention policy properties
|
|
36
37
|
property :manage, T::Boolean, optional: true, default: false,
|
|
@@ -93,8 +94,6 @@ module ZfsMgmt
|
|
|
93
94
|
description: 'Pass -h (drop holds) to zfs recv'
|
|
94
95
|
property :recv_unmount, T::Boolean, optional: true, default: false,
|
|
95
96
|
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
97
|
property :recv_discard_first, T::Boolean, optional: true, default: false,
|
|
99
98
|
description: 'Pass -d (discard first path element) to zfs recv'
|
|
100
99
|
property :recv_force, T::Boolean, optional: true, default: false,
|
|
@@ -111,6 +110,7 @@ module ZfsMgmt
|
|
|
111
110
|
attrs = attributes.transform_keys(&:to_sym)
|
|
112
111
|
@snapshots = attrs.delete(:snapshots) if attrs.key?(:snapshots)
|
|
113
112
|
@destination_relative_path = attrs.delete(:destination_relative_path) if attrs.key?(:destination_relative_path)
|
|
113
|
+
@destination_base = attrs.delete(:destination_base) if attrs.key?(:destination_base)
|
|
114
114
|
if attrs.key?(:send) && !attrs.key?(:send_enabled)
|
|
115
115
|
attrs[:send_enabled] = attrs.delete(:send)
|
|
116
116
|
end
|
|
@@ -125,6 +125,10 @@ module ZfsMgmt
|
|
|
125
125
|
send_enabled == true
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
+
def volume?
|
|
129
|
+
type == 'volume'
|
|
130
|
+
end
|
|
131
|
+
|
|
128
132
|
def snapshots
|
|
129
133
|
return @snapshots unless @snapshots.nil?
|
|
130
134
|
|
|
@@ -155,9 +159,24 @@ module ZfsMgmt
|
|
|
155
159
|
File.join(override, rel)
|
|
156
160
|
end
|
|
157
161
|
|
|
162
|
+
def base_destination(override = nil)
|
|
163
|
+
return override if override
|
|
164
|
+
|
|
165
|
+
@destination_base || destination
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def discard_first_destination(override = nil)
|
|
169
|
+
base = base_destination(override)
|
|
170
|
+
return nil unless base
|
|
171
|
+
|
|
172
|
+
rel = name.include?('/') ? name.split('/', 2).last : nil
|
|
173
|
+
rel && !rel.empty? ? File.join(base, rel) : base
|
|
174
|
+
end
|
|
175
|
+
|
|
158
176
|
def self.from_zfs_props(name, props = {})
|
|
159
177
|
props ||= {}
|
|
160
178
|
attrs = { name: name }
|
|
179
|
+
attrs[:type] = props['type'] if props.key?('type')
|
|
161
180
|
|
|
162
181
|
attrs[:manage] = ZfsMgmt.prop_on?(props['zfsmgmt:manage'])
|
|
163
182
|
attrs[:policy] = props['zfsmgmt:policy'] if props.key?('zfsmgmt:policy')
|
|
@@ -214,10 +233,12 @@ module ZfsMgmt
|
|
|
214
233
|
rel = File.basename(name)
|
|
215
234
|
attrs[:destination] = File.join(dest_base, rel)
|
|
216
235
|
attrs[:destination_relative_path] = rel
|
|
236
|
+
attrs[:destination_base] = dest_base
|
|
217
237
|
elsif dest_src && (m = /\Ainherited from (.+)\z/.match(dest_src))
|
|
218
238
|
rel = File.join(File.basename(m[1]), name.sub(m[1], ''))
|
|
219
239
|
attrs[:destination] = File.join(dest_base, rel)
|
|
220
240
|
attrs[:destination_relative_path] = rel
|
|
241
|
+
attrs[:destination_base] = dest_base
|
|
221
242
|
end
|
|
222
243
|
end
|
|
223
244
|
|
|
@@ -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
|