zfs_mgmt 0.6.0 → 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 +1 -0
- data/Gemfile.lock +46 -2
- data/bin/zfsmgr +6 -0
- data/lib/zfs_mgmt/restic.rb +10 -7
- data/lib/zfs_mgmt/version.rb +1 -1
- data/lib/zfs_mgmt/zfs.rb +263 -0
- data/lib/zfs_mgmt/zfs_mgr/list.rb +7 -3
- data/lib/zfs_mgmt/zfs_mgr/send.rb +0 -1
- data/lib/zfs_mgmt.rb +162 -127
- data/zfs_mgmt.gemspec +1 -0
- metadata +21 -10
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
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
zfs_mgmt (0.
|
|
4
|
+
zfs_mgmt (0.7.2)
|
|
5
|
+
easy_talk
|
|
5
6
|
filesize (~> 0.2)
|
|
6
7
|
pstore
|
|
7
8
|
text-table (~> 1.2)
|
|
@@ -10,19 +11,56 @@ PATH
|
|
|
10
11
|
GEM
|
|
11
12
|
remote: https://rubygems.org/
|
|
12
13
|
specs:
|
|
14
|
+
activemodel (8.1.4.1)
|
|
15
|
+
activesupport (= 8.1.4.1)
|
|
16
|
+
activesupport (8.1.4.1)
|
|
17
|
+
base64
|
|
18
|
+
bigdecimal
|
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
20
|
+
connection_pool (>= 2.2.5)
|
|
21
|
+
drb
|
|
22
|
+
i18n (>= 1.6, < 2)
|
|
23
|
+
json
|
|
24
|
+
logger (>= 1.4.2)
|
|
25
|
+
minitest (>= 5.1)
|
|
26
|
+
securerandom (>= 0.3)
|
|
27
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
28
|
+
uri (>= 0.13.1)
|
|
29
|
+
base64 (0.3.0)
|
|
30
|
+
bigdecimal (4.1.3)
|
|
31
|
+
character_set (1.9.0)
|
|
32
|
+
concurrent-ruby (1.3.8)
|
|
33
|
+
connection_pool (3.0.3)
|
|
13
34
|
diff-lcs (1.6.2)
|
|
14
35
|
docile (1.4.1)
|
|
36
|
+
drb (2.2.3)
|
|
37
|
+
easy_talk (3.3.2)
|
|
38
|
+
activemodel (>= 7.0, < 9.0)
|
|
39
|
+
activesupport (>= 7.0, < 9.0)
|
|
40
|
+
js_regex (~> 3.0)
|
|
41
|
+
sorbet-runtime (~> 0.5)
|
|
15
42
|
filesize (0.2.0)
|
|
43
|
+
i18n (1.15.2)
|
|
44
|
+
concurrent-ruby (~> 1.0)
|
|
45
|
+
js_regex (3.15.0)
|
|
46
|
+
character_set (~> 1.4)
|
|
47
|
+
regexp_parser (~> 2.11)
|
|
48
|
+
regexp_property_values (~> 1.0)
|
|
16
49
|
json (3.1.0)
|
|
17
50
|
language_server-protocol (3.17.0.6)
|
|
18
51
|
logger (1.7.0)
|
|
52
|
+
minitest (6.1.0)
|
|
53
|
+
drb (~> 2.0)
|
|
54
|
+
prism (>= 1.5, < 3)
|
|
19
55
|
prism (1.9.0)
|
|
20
56
|
pstore (0.2.1)
|
|
21
57
|
rake (13.4.2)
|
|
22
|
-
rbs (4.
|
|
58
|
+
rbs (4.2.0)
|
|
23
59
|
logger
|
|
24
60
|
prism (>= 1.6.0)
|
|
25
61
|
tsort
|
|
62
|
+
regexp_parser (2.13.4)
|
|
63
|
+
regexp_property_values (1.5.2)
|
|
26
64
|
rspec (3.13.2)
|
|
27
65
|
rspec-core (~> 3.13.0)
|
|
28
66
|
rspec-expectations (~> 3.13.0)
|
|
@@ -40,22 +78,28 @@ GEM
|
|
|
40
78
|
language_server-protocol (~> 3.17.0)
|
|
41
79
|
prism (>= 1.2, < 2.0)
|
|
42
80
|
rbs (>= 3, < 5)
|
|
81
|
+
securerandom (0.4.1)
|
|
43
82
|
simplecov (0.22.0)
|
|
44
83
|
docile (~> 1.1)
|
|
45
84
|
simplecov-html (~> 0.11)
|
|
46
85
|
simplecov_json_formatter (~> 0.1)
|
|
47
86
|
simplecov-html (0.13.2)
|
|
48
87
|
simplecov_json_formatter (0.1.4)
|
|
88
|
+
sorbet-runtime (0.6.13715)
|
|
49
89
|
text-table (1.2.4)
|
|
50
90
|
thor (1.5.0)
|
|
51
91
|
timeout (0.6.1)
|
|
52
92
|
tsort (0.2.0)
|
|
93
|
+
tzinfo (2.0.6)
|
|
94
|
+
concurrent-ruby (~> 1.0)
|
|
95
|
+
uri (1.1.2)
|
|
53
96
|
|
|
54
97
|
PLATFORMS
|
|
55
98
|
x86_64-linux
|
|
56
99
|
|
|
57
100
|
DEPENDENCIES
|
|
58
101
|
bundler (>= 2.2.33)
|
|
102
|
+
easy_talk
|
|
59
103
|
filesize
|
|
60
104
|
json
|
|
61
105
|
pstore
|
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/restic.rb
CHANGED
|
@@ -12,10 +12,11 @@ module ZfsMgmt::Restic
|
|
|
12
12
|
if options.has_key?('password_file')
|
|
13
13
|
com.push('-p',options['password_file'])
|
|
14
14
|
end
|
|
15
|
+
repo = props.is_a?(ZfsMgmt::Zfs) ? props.restic_repository : props['zfsmgmt:restic_repository']
|
|
15
16
|
if options.has_key?('repo')
|
|
16
17
|
com.push('--repo', options['repo'])
|
|
17
|
-
elsif
|
|
18
|
-
com.push( '--repo',
|
|
18
|
+
elsif repo
|
|
19
|
+
com.push( '--repo', repo )
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
$logger.info("#{com.join(' ')}")
|
|
@@ -70,8 +71,10 @@ module ZfsMgmt::Restic
|
|
|
70
71
|
'zfsmgmt:restic_repository',
|
|
71
72
|
'userrefs',
|
|
72
73
|
],
|
|
73
|
-
property_match: {
|
|
74
|
-
zfs
|
|
74
|
+
property_match: { restic_backup: true }).each do |zfs_obj|
|
|
75
|
+
zfs = zfs_obj.name
|
|
76
|
+
zfs_snapshots = zfs_obj.snapshots
|
|
77
|
+
next if zfs_snapshots.empty?
|
|
75
78
|
last_zfs_snapshot = zfs_snapshots.keys.sort { |a,b| zfs_snapshots[a]['creation'] <=> zfs_snapshots[b]['creation'] }.last
|
|
76
79
|
zfs_snap_time = Time.at(zfs_snapshots[last_zfs_snapshot]['creation'])
|
|
77
80
|
|
|
@@ -79,7 +82,7 @@ module ZfsMgmt::Restic
|
|
|
79
82
|
chain = []
|
|
80
83
|
zfs_snap_parent = ''
|
|
81
84
|
restic_snap_parent = ''
|
|
82
|
-
(restic_snapshots,restic_snapshot_zfs_snapshot_index) = restic_snapshots(zfs,options,
|
|
85
|
+
(restic_snapshots,restic_snapshot_zfs_snapshot_index) = restic_snapshots(zfs,options,zfs_obj)
|
|
83
86
|
if restic_snapshot_zfs_snapshot_index.has_key?(last_zfs_snapshot)
|
|
84
87
|
$logger.warn("backup of this snapshot #{last_zfs_snapshot} already exists in restic, cannot continue with backup of #{zfs}")
|
|
85
88
|
next # next zfs filesystem to be backed up
|
|
@@ -132,8 +135,8 @@ module ZfsMgmt::Restic
|
|
|
132
135
|
end
|
|
133
136
|
if options.has_key?('repo')
|
|
134
137
|
com.push('--repo', options['repo'])
|
|
135
|
-
elsif
|
|
136
|
-
com.push( '--repo',
|
|
138
|
+
elsif zfs_obj.restic_repository
|
|
139
|
+
com.push( '--repo', zfs_obj.restic_repository )
|
|
137
140
|
end
|
|
138
141
|
if options[:verbose]
|
|
139
142
|
com.push('--verbose',options[:verbose])
|
data/lib/zfs_mgmt/version.rb
CHANGED
data/lib/zfs_mgmt/zfs.rb
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
require 'easy_talk'
|
|
3
|
+
|
|
4
|
+
module ZfsMgmt
|
|
5
|
+
class Zfs
|
|
6
|
+
include EasyTalk::Model
|
|
7
|
+
|
|
8
|
+
SEND_BOOL_PROPS = %i[
|
|
9
|
+
send_intermediary
|
|
10
|
+
send_backup
|
|
11
|
+
send_compressed
|
|
12
|
+
send_embed
|
|
13
|
+
send_holds
|
|
14
|
+
send_large_block
|
|
15
|
+
send_props
|
|
16
|
+
send_raw
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
19
|
+
RECV_BOOL_PROPS = %i[
|
|
20
|
+
recv_noop
|
|
21
|
+
recv_drop_holds
|
|
22
|
+
recv_unmount
|
|
23
|
+
recv_discard_first
|
|
24
|
+
recv_force
|
|
25
|
+
].freeze
|
|
26
|
+
|
|
27
|
+
define_schema do
|
|
28
|
+
title 'Zfs'
|
|
29
|
+
description 'Encapsulates zfsmgmt:* user properties for a ZFS dataset'
|
|
30
|
+
|
|
31
|
+
property :name, String,
|
|
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)'
|
|
35
|
+
|
|
36
|
+
# Snapshot retention policy properties
|
|
37
|
+
property :manage, T::Boolean, optional: true, default: false,
|
|
38
|
+
description: 'Whether snapshot retention management is enabled for this dataset'
|
|
39
|
+
property :policy, String, optional: true, pattern: '\A(\d+[hdwmyHDWMY])+\z',
|
|
40
|
+
description: 'Snapshot retention policy specification (e.g. 10y60m104w365d168h)'
|
|
41
|
+
property :strategy, String, optional: true, enum: %w[oldest youngest], default: 'oldest',
|
|
42
|
+
description: 'Which snapshot to retain within each policy timeframe'
|
|
43
|
+
property :minage, String, optional: true, pattern: '\A\d+[smhdwSMHDW]?\z',
|
|
44
|
+
description: 'Minimum age before a snapshot is eligible for destruction (e.g. 7D)'
|
|
45
|
+
property :matchsnaps, String, optional: true,
|
|
46
|
+
description: 'Regular expression that snapshot names must match to satisfy retention policy'
|
|
47
|
+
property :ignoresnaps, String, optional: true,
|
|
48
|
+
description: 'Regular expression for snapshot names to ignore during policy evaluation and destruction'
|
|
49
|
+
property :prefersnaps, String, optional: true,
|
|
50
|
+
description: 'Regular expression for snapshot names preferred when selecting snapshots to retain'
|
|
51
|
+
|
|
52
|
+
# Snapshot creation properties
|
|
53
|
+
property :snapshot, T::Boolean, optional: true, default: false,
|
|
54
|
+
description: 'Whether snapshots should be created for this dataset'
|
|
55
|
+
property :snapshot_recursive, T::Boolean, optional: true, default: false,
|
|
56
|
+
description: 'Whether snapshots should be created recursively (-r) for this dataset'
|
|
57
|
+
property :snap_prefix, String, optional: true, default: 'zfsmgmt',
|
|
58
|
+
description: 'Prefix used when naming created snapshots'
|
|
59
|
+
property :snap_timestamp, String, optional: true, default: '%FT%T%z',
|
|
60
|
+
description: 'strftime format string used when naming created snapshots'
|
|
61
|
+
|
|
62
|
+
# ZFS send/recv properties
|
|
63
|
+
property :send_enabled, T::Boolean, optional: true, default: false, as: :send,
|
|
64
|
+
description: 'Whether zfs send is enabled for this dataset'
|
|
65
|
+
property :remote, String, optional: true,
|
|
66
|
+
description: 'Remote SSH target for zfs recv (e.g. user@host)'
|
|
67
|
+
property :destination, String, optional: true,
|
|
68
|
+
description: 'Resolved destination ZFS dataset path for zfs send/recv'
|
|
69
|
+
|
|
70
|
+
property :send_intermediary, T::Boolean, optional: true, default: false,
|
|
71
|
+
description: 'Pass -I (intermediary snapshots) to zfs send'
|
|
72
|
+
property :send_backup, T::Boolean, optional: true, default: false,
|
|
73
|
+
description: 'Pass -b (backup) to zfs send'
|
|
74
|
+
property :send_compressed, T::Boolean, optional: true, default: false,
|
|
75
|
+
description: 'Pass -c (compressed) to zfs send'
|
|
76
|
+
property :send_embed, T::Boolean, optional: true, default: false,
|
|
77
|
+
description: 'Pass -e (embed) to zfs send'
|
|
78
|
+
property :send_holds, T::Boolean, optional: true, default: false,
|
|
79
|
+
description: 'Pass -h (holds) to zfs send'
|
|
80
|
+
property :send_large_block, T::Boolean, optional: true, default: false,
|
|
81
|
+
description: 'Pass -L (large block) to zfs send'
|
|
82
|
+
property :send_props, T::Boolean, optional: true, default: false,
|
|
83
|
+
description: 'Pass -p (properties) to zfs send'
|
|
84
|
+
property :send_raw, T::Boolean, optional: true, default: false,
|
|
85
|
+
description: 'Pass -w (raw) to zfs send'
|
|
86
|
+
property :send_replicate, T::Boolean, optional: true, default: false,
|
|
87
|
+
description: 'Pass -R (replicate) to zfs send'
|
|
88
|
+
|
|
89
|
+
property :recv_state, T::Boolean, optional: true, default: true,
|
|
90
|
+
description: 'Pass -s (save partial receive state) to zfs recv'
|
|
91
|
+
property :recv_noop, T::Boolean, optional: true, default: false,
|
|
92
|
+
description: 'Pass -n (noop) to zfs recv'
|
|
93
|
+
property :recv_drop_holds, T::Boolean, optional: true, default: false,
|
|
94
|
+
description: 'Pass -h (drop holds) to zfs recv'
|
|
95
|
+
property :recv_unmount, T::Boolean, optional: true, default: false,
|
|
96
|
+
description: 'Pass -u (unmount) to zfs recv'
|
|
97
|
+
property :recv_discard_first, T::Boolean, optional: true, default: false,
|
|
98
|
+
description: 'Pass -d (discard first path element) to zfs recv'
|
|
99
|
+
property :recv_force, T::Boolean, optional: true, default: false,
|
|
100
|
+
description: 'Pass -F (force rollback) to zfs recv'
|
|
101
|
+
|
|
102
|
+
# Restic backup properties
|
|
103
|
+
property :restic_backup, T::Boolean, optional: true, default: false,
|
|
104
|
+
description: 'Whether restic backup is enabled for this dataset'
|
|
105
|
+
property :restic_repository, String, optional: true,
|
|
106
|
+
description: 'Target restic repository for backups'
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def initialize(attributes = {})
|
|
110
|
+
attrs = attributes.transform_keys(&:to_sym)
|
|
111
|
+
@snapshots = attrs.delete(:snapshots) if attrs.key?(:snapshots)
|
|
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
|
+
if attrs.key?(:send) && !attrs.key?(:send_enabled)
|
|
115
|
+
attrs[:send_enabled] = attrs.delete(:send)
|
|
116
|
+
end
|
|
117
|
+
super(attrs)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def send=(value)
|
|
121
|
+
self.send_enabled = value
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def send?
|
|
125
|
+
send_enabled == true
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def volume?
|
|
129
|
+
type == 'volume'
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def snapshots
|
|
133
|
+
return @snapshots unless @snapshots.nil?
|
|
134
|
+
|
|
135
|
+
@snapshots = ZfsMgmt.zfsget(
|
|
136
|
+
properties: %w[name creation userrefs used written referenced],
|
|
137
|
+
types: ['snapshot'],
|
|
138
|
+
zfs: name
|
|
139
|
+
)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def snapshots=(value)
|
|
143
|
+
@snapshots = value
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def snapshots_loaded?
|
|
147
|
+
!@snapshots.nil?
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def reload_snapshots!
|
|
151
|
+
@snapshots = nil
|
|
152
|
+
snapshots
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def resolved_destination(override = nil)
|
|
156
|
+
return destination unless override
|
|
157
|
+
|
|
158
|
+
rel = @destination_relative_path || File.basename(name)
|
|
159
|
+
File.join(override, rel)
|
|
160
|
+
end
|
|
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
|
+
|
|
176
|
+
def self.from_zfs_props(name, props = {})
|
|
177
|
+
props ||= {}
|
|
178
|
+
attrs = { name: name }
|
|
179
|
+
attrs[:type] = props['type'] if props.key?('type')
|
|
180
|
+
|
|
181
|
+
attrs[:manage] = ZfsMgmt.prop_on?(props['zfsmgmt:manage'])
|
|
182
|
+
attrs[:policy] = props['zfsmgmt:policy'] if props.key?('zfsmgmt:policy')
|
|
183
|
+
attrs[:strategy] = props['zfsmgmt:strategy'] if props.key?('zfsmgmt:strategy')
|
|
184
|
+
attrs[:minage] = props['zfsmgmt:minage'] if props.key?('zfsmgmt:minage')
|
|
185
|
+
attrs[:matchsnaps] = props['zfsmgmt:matchsnaps'] if props.key?('zfsmgmt:matchsnaps')
|
|
186
|
+
attrs[:ignoresnaps] = props['zfsmgmt:ignoresnaps'] if props.key?('zfsmgmt:ignoresnaps')
|
|
187
|
+
attrs[:prefersnaps] = props['zfsmgmt:prefersnaps'] if props.key?('zfsmgmt:prefersnaps')
|
|
188
|
+
|
|
189
|
+
# Interpret zfsmgmt:snapshot taking its @source into account
|
|
190
|
+
snap_val = props['zfsmgmt:snapshot']
|
|
191
|
+
snap_src = props['zfsmgmt:snapshot@source']
|
|
192
|
+
if ZfsMgmt.prop_on?(snap_val)
|
|
193
|
+
attrs[:snapshot] = true
|
|
194
|
+
attrs[:snapshot_recursive] = false
|
|
195
|
+
elsif %w[recursive local].include?(snap_val) && %w[local received].include?(snap_src)
|
|
196
|
+
attrs[:snapshot] = true
|
|
197
|
+
attrs[:snapshot_recursive] = (snap_val == 'recursive')
|
|
198
|
+
else
|
|
199
|
+
attrs[:snapshot] = false
|
|
200
|
+
attrs[:snapshot_recursive] = false
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
attrs[:snap_prefix] = props['zfsmgmt:snap_prefix'] if props.key?('zfsmgmt:snap_prefix')
|
|
204
|
+
attrs[:snap_timestamp] = props['zfsmgmt:snap_timestamp'] if props.key?('zfsmgmt:snap_timestamp')
|
|
205
|
+
|
|
206
|
+
# Interpret zfsmgmt:send and zfsmgmt:send_replicate taking @source into account
|
|
207
|
+
send_val = props['zfsmgmt:send']
|
|
208
|
+
send_src = props['zfsmgmt:send@source']
|
|
209
|
+
rep_val = props['zfsmgmt:send_replicate']
|
|
210
|
+
rep_src = props['zfsmgmt:send_replicate@source']
|
|
211
|
+
|
|
212
|
+
replicated_descendant = ZfsMgmt.prop_on?(rep_val) && !rep_src.nil? && rep_src != 'local'
|
|
213
|
+
attrs[:send_replicate] = ZfsMgmt.prop_on?(rep_val) && !replicated_descendant
|
|
214
|
+
|
|
215
|
+
attrs[:send_enabled] =
|
|
216
|
+
if send_src == 'received' || replicated_descendant
|
|
217
|
+
false
|
|
218
|
+
elsif ZfsMgmt.prop_on?(send_val)
|
|
219
|
+
true
|
|
220
|
+
elsif send_val == 'local' && send_src == 'local'
|
|
221
|
+
true
|
|
222
|
+
else
|
|
223
|
+
false
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
attrs[:remote] = props['zfsmgmt:remote'] if props.key?('zfsmgmt:remote')
|
|
227
|
+
|
|
228
|
+
# Interpret zfsmgmt:destination taking @source into account
|
|
229
|
+
if props.key?('zfsmgmt:destination')
|
|
230
|
+
dest_base = props['zfsmgmt:destination']
|
|
231
|
+
dest_src = props['zfsmgmt:destination@source']
|
|
232
|
+
if dest_src == 'local'
|
|
233
|
+
rel = File.basename(name)
|
|
234
|
+
attrs[:destination] = File.join(dest_base, rel)
|
|
235
|
+
attrs[:destination_relative_path] = rel
|
|
236
|
+
attrs[:destination_base] = dest_base
|
|
237
|
+
elsif dest_src && (m = /\Ainherited from (.+)\z/.match(dest_src))
|
|
238
|
+
rel = File.join(File.basename(m[1]), name.sub(m[1], ''))
|
|
239
|
+
attrs[:destination] = File.join(dest_base, rel)
|
|
240
|
+
attrs[:destination_relative_path] = rel
|
|
241
|
+
attrs[:destination_base] = dest_base
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
SEND_BOOL_PROPS.each do |prop|
|
|
246
|
+
key = "zfsmgmt:#{prop}"
|
|
247
|
+
attrs[prop] = ZfsMgmt.prop_on?(props[key]) if props.key?(key)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
attrs[:recv_state] = !ZfsMgmt.prop_off?(props['zfsmgmt:recv_state']) if props.key?('zfsmgmt:recv_state')
|
|
251
|
+
|
|
252
|
+
RECV_BOOL_PROPS.each do |prop|
|
|
253
|
+
key = "zfsmgmt:#{prop}"
|
|
254
|
+
attrs[prop] = ZfsMgmt.prop_on?(props[key]) if props.key?(key)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
attrs[:restic_backup] = ZfsMgmt.prop_on?(props['zfsmgmt:restic_backup']) if props.key?('zfsmgmt:restic_backup')
|
|
258
|
+
attrs[:restic_repository] = props['zfsmgmt:restic_repository'] if props.key?('zfsmgmt:restic_repository')
|
|
259
|
+
|
|
260
|
+
new(attrs)
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
@@ -13,11 +13,13 @@ class ZfsMgmt::ZfsMgr::List < Thor
|
|
|
13
13
|
table = Text::Table.new
|
|
14
14
|
table.head = ['zfs','snapshot','age']
|
|
15
15
|
table.rows = []
|
|
16
|
-
ZfsMgmt.zfs_managed_list(filter: options[:filter]).each do |zfs
|
|
16
|
+
ZfsMgmt.zfs_managed_list(filter: options[:filter]).each do |zfs|
|
|
17
|
+
snaps = zfs.snapshots
|
|
18
|
+
next if snaps.empty?
|
|
17
19
|
last = snaps.keys.sort { |a,b| snaps[a]['creation'] <=> snaps[b]['creation'] }.last
|
|
18
20
|
snap_time = Time.at(snaps[last]['creation'])
|
|
19
21
|
if snap_time < cutoff
|
|
20
|
-
line = [zfs,last.split('@')[1],snap_time]
|
|
22
|
+
line = [zfs.name,last.split('@')[1],snap_time]
|
|
21
23
|
table.rows << line
|
|
22
24
|
if options[:format] == 'tab'
|
|
23
25
|
print line.join("\t"),"\n"
|
|
@@ -36,7 +38,9 @@ class ZfsMgmt::ZfsMgr::List < Thor
|
|
|
36
38
|
table = Text::Table.new
|
|
37
39
|
table.head = ['snapshot','userrefs','holds']
|
|
38
40
|
table.rows = []
|
|
39
|
-
ZfsMgmt.zfs_managed_list(filter: options[:filter], property_match: {} ).each do |zfs
|
|
41
|
+
ZfsMgmt.zfs_managed_list(filter: options[:filter], property_match: {} ).each do |zfs|
|
|
42
|
+
snaps = zfs.snapshots
|
|
43
|
+
next if snaps.empty?
|
|
40
44
|
snaps.sort_by { |x,y| y['creation'] }.each do |snap,d|
|
|
41
45
|
if d['userrefs'] > 0
|
|
42
46
|
line = [snap,d['userrefs'].to_s,ZfsMgmt.zfs_holds(snap).join(',')]
|
|
@@ -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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
require "zfs_mgmt/version"
|
|
3
3
|
require "thor"
|
|
4
|
+
require "zfs_mgmt/zfs"
|
|
4
5
|
require "zfs_mgmt/restic"
|
|
5
6
|
require "zfs_mgmt/zfs_mgr"
|
|
6
7
|
require 'pp'
|
|
@@ -176,18 +177,25 @@ module ZfsMgmt
|
|
|
176
177
|
end
|
|
177
178
|
return [results['hourly'],results['daily'],results['weekly'],results['monthly'],results['yearly']]
|
|
178
179
|
end
|
|
179
|
-
def self.snapshot_destroy_policy(zfs,props,snaps)
|
|
180
|
+
def self.snapshot_destroy_policy(zfs, props = nil, snaps = nil)
|
|
181
|
+
if zfs.is_a?(ZfsMgmt::Zfs)
|
|
182
|
+
zfs_obj = zfs
|
|
183
|
+
snaps ||= zfs_obj.snapshots
|
|
184
|
+
else
|
|
185
|
+
zfs_obj = ZfsMgmt::Zfs.from_zfs_props(zfs, props)
|
|
186
|
+
end
|
|
187
|
+
|
|
180
188
|
minage = 0
|
|
181
|
-
if
|
|
182
|
-
minage = timespec_to_seconds(
|
|
189
|
+
if zfs_obj.minage
|
|
190
|
+
minage = timespec_to_seconds(zfs_obj.minage)
|
|
183
191
|
end
|
|
184
192
|
strategy = 'oldest'
|
|
185
|
-
if
|
|
193
|
+
if zfs_obj.strategy == 'youngest'
|
|
186
194
|
strategy = 'youngest'
|
|
187
195
|
end
|
|
188
196
|
sorted = snaps.keys.sort { |a,b| snaps[b]['creation'] <=> snaps[a]['creation'] }
|
|
189
197
|
|
|
190
|
-
counters = policy_parser(
|
|
198
|
+
counters = policy_parser(zfs_obj.policy)
|
|
191
199
|
$logger.debug(counters)
|
|
192
200
|
saved = {}
|
|
193
201
|
|
|
@@ -197,23 +205,22 @@ module ZfsMgmt
|
|
|
197
205
|
end
|
|
198
206
|
|
|
199
207
|
sorted.each do |snap_name|
|
|
200
|
-
if
|
|
201
|
-
$logger.debug("skipping #{snap_name} because it matches ignoresnaps pattern: #{
|
|
208
|
+
if zfs_obj.ignoresnaps and /#{zfs_obj.ignoresnaps}/ =~ snap_name.split('@')[1]
|
|
209
|
+
$logger.debug("skipping #{snap_name} because it matches ignoresnaps pattern: #{zfs_obj.ignoresnaps}")
|
|
202
210
|
next
|
|
203
211
|
end
|
|
204
|
-
if
|
|
205
|
-
$logger.debug("skipping #{snap_name} because it does not match matchsnaps pattern: #{
|
|
212
|
+
if zfs_obj.matchsnaps and not /#{zfs_obj.matchsnaps}/ =~ snap_name.split('@')[1]
|
|
213
|
+
$logger.debug("skipping #{snap_name} because it does not match matchsnaps pattern: #{zfs_obj.matchsnaps}")
|
|
206
214
|
next
|
|
207
215
|
end
|
|
208
216
|
snaptime = local_epoch_to_datetime(snaps[snap_name]['creation'])
|
|
209
217
|
$date_patterns.each do |d,p|
|
|
210
218
|
pat = snaptime.strftime(p)
|
|
211
219
|
if saved[d].has_key?(pat)
|
|
212
|
-
|
|
213
|
-
if props.has_key?('zfsmgmt:prefersnaps') and /#{props['zfsmgmt:prefersnaps']}/ !~ saved[d][pat].split('@')[1] and /#{props['zfsmgmt:prefersnaps']}/ =~ snap_name.split('@')[1]
|
|
220
|
+
if zfs_obj.prefersnaps and /#{zfs_obj.prefersnaps}/ !~ saved[d][pat].split('@')[1] and /#{zfs_obj.prefersnaps}/ =~ snap_name.split('@')[1]
|
|
214
221
|
$logger.debug("updating the saved snapshot, we prefer this one: \"#{pat}\" to #{snap_name} at #{snaptime}")
|
|
215
222
|
saved[d][pat] = snap_name
|
|
216
|
-
elsif strategy == 'oldest' and ( not
|
|
223
|
+
elsif strategy == 'oldest' and ( not zfs_obj.prefersnaps or /#{zfs_obj.prefersnaps}/ =~ snap_name.split('@')[1] )
|
|
217
224
|
# update the existing current save snapshot for this timeframe
|
|
218
225
|
$logger.debug("updating the saved snapshot for \"#{pat}\" to #{snap_name} at #{snaptime}")
|
|
219
226
|
saved[d][pat] = snap_name
|
|
@@ -239,8 +246,8 @@ module ZfsMgmt
|
|
|
239
246
|
# delete everything not in the list of saved snapshots
|
|
240
247
|
deleteme = sorted - saved_snaps
|
|
241
248
|
deleteme = deleteme.select { |snap|
|
|
242
|
-
if
|
|
243
|
-
$logger.debug("skipping #{snap} because it matches ignoresnaps pattern: #{
|
|
249
|
+
if zfs_obj.ignoresnaps and /#{zfs_obj.ignoresnaps}/ =~ snap.split('@')[1]
|
|
250
|
+
$logger.debug("skipping #{snap} because it matches ignoresnaps pattern: #{zfs_obj.ignoresnaps}")
|
|
244
251
|
false
|
|
245
252
|
elsif minage > 0 and Time.at(snaps[snap]['creation'] + minage) > Time.now()
|
|
246
253
|
$logger.debug("skipping due to minage: #{snap} #{local_epoch_to_datetime(snaps[snap]['creation']).strftime('%F %T')}")
|
|
@@ -254,53 +261,61 @@ module ZfsMgmt
|
|
|
254
261
|
}
|
|
255
262
|
return saved,saved_snaps,deleteme
|
|
256
263
|
end
|
|
257
|
-
def self.zfs_managed_list(filter: '.+', properties: ['all'], property_match: {
|
|
258
|
-
zfss = []
|
|
259
|
-
zfsget(properties: properties).each do |
|
|
260
|
-
unless
|
|
264
|
+
def self.zfs_managed_list(filter: '.+', properties: ['all'], property_match: { manage: true } )
|
|
265
|
+
zfss = []
|
|
266
|
+
zfsget(properties: properties).each do |zfs_name,props|
|
|
267
|
+
unless match_filter?(zfs_name, filter)
|
|
261
268
|
next
|
|
262
269
|
end
|
|
270
|
+
zfs = ZfsMgmt::Zfs.from_zfs_props(zfs_name, props)
|
|
263
271
|
managed = true
|
|
264
272
|
property_match.each do |k,v|
|
|
265
|
-
|
|
273
|
+
matched = if k.to_s.start_with?('zfsmgmt:')
|
|
274
|
+
key_comp?(props, k, v)
|
|
275
|
+
else
|
|
276
|
+
attr_name = (k.to_sym == :send ? :send_enabled : k.to_sym)
|
|
277
|
+
match_value?(zfs.public_send(attr_name), v)
|
|
278
|
+
end
|
|
279
|
+
unless matched
|
|
266
280
|
managed = false
|
|
267
281
|
break
|
|
268
282
|
end
|
|
269
283
|
end
|
|
270
284
|
next unless managed
|
|
271
|
-
|
|
272
|
-
if snaps.length == 0
|
|
273
|
-
$logger.debug("not processing #{zfs} as there are no snapshots")
|
|
274
|
-
next
|
|
275
|
-
end
|
|
276
|
-
zfss.push([zfs,props,snaps])
|
|
285
|
+
zfss.push(zfs)
|
|
277
286
|
end
|
|
278
287
|
return zfss
|
|
279
288
|
end
|
|
280
289
|
def self.snapshot_policy(filter: '.+', show_destroy: false)
|
|
281
|
-
zfs_managed_list(filter: filter).each do |zfs
|
|
282
|
-
unless
|
|
283
|
-
$logger.error("zfs_mgmt is configured to manage #{zfs}, but there is no policy configuration in zfsmgmt:policy, skipping")
|
|
290
|
+
zfs_managed_list(filter: filter).each do |zfs|
|
|
291
|
+
unless zfs.policy
|
|
292
|
+
$logger.error("zfs_mgmt is configured to manage #{zfs.name}, but there is no policy configuration in zfsmgmt:policy, skipping")
|
|
284
293
|
next # zfs
|
|
285
294
|
end
|
|
286
295
|
|
|
296
|
+
snaps = zfs.snapshots
|
|
297
|
+
if snaps.empty?
|
|
298
|
+
$logger.debug("not processing #{zfs.name} as there are no snapshots")
|
|
299
|
+
next
|
|
300
|
+
end
|
|
301
|
+
|
|
287
302
|
begin
|
|
288
303
|
# call the function that decides who to save and who to delete
|
|
289
|
-
(saved,saved_snaps,deleteme) = snapshot_destroy_policy(zfs
|
|
304
|
+
(saved,saved_snaps,deleteme) = snapshot_destroy_policy(zfs)
|
|
290
305
|
rescue ArgumentError
|
|
291
|
-
$logger.error("zfs_mgmt is configured to manage #{zfs}, but there is no valid policy configuration, skipping")
|
|
306
|
+
$logger.error("zfs_mgmt is configured to manage #{zfs.name}, but there is no valid policy configuration, skipping")
|
|
292
307
|
next
|
|
293
308
|
end
|
|
294
309
|
|
|
295
310
|
snaps_to_show = show_destroy ? (saved_snaps + deleteme).uniq : saved_snaps
|
|
296
311
|
|
|
297
312
|
if snaps_to_show.length == 0
|
|
298
|
-
$logger.info("no snapshots marked as saved by policy for #{zfs}")
|
|
313
|
+
$logger.info("no snapshots marked as saved by policy for #{zfs.name}")
|
|
299
314
|
next
|
|
300
315
|
end
|
|
301
316
|
# print a table of saved snapshots with the reasons it is being saved
|
|
302
317
|
table = Text::Table.new
|
|
303
|
-
table.head = [zfs,'creation','hourly','daily','weekly','monthly','yearly']
|
|
318
|
+
table.head = [zfs.name,'creation','hourly','daily','weekly','monthly','yearly']
|
|
304
319
|
table.rows = []
|
|
305
320
|
snaps_to_show.sort { |a,b| snaps[b]['creation'] <=> snaps[a]['creation'] }.each do |snap|
|
|
306
321
|
table.rows << [snap.split('@')[1],local_epoch_to_datetime(snaps[snap]['creation'])] + find_saved_reason(saved,snap)
|
|
@@ -309,21 +324,27 @@ module ZfsMgmt
|
|
|
309
324
|
end
|
|
310
325
|
end
|
|
311
326
|
def self.snapshot_destroy(noop: false, verbose: false, filter: '.+')
|
|
312
|
-
zfs_managed_list(filter: filter).each do |zfs
|
|
313
|
-
unless
|
|
314
|
-
$logger.error("zfs_mgmt is configured to manage #{zfs}, but there is no policy configuration in zfsmgmt:policy, skipping")
|
|
327
|
+
zfs_managed_list(filter: filter).each do |zfs|
|
|
328
|
+
unless zfs.policy
|
|
329
|
+
$logger.error("zfs_mgmt is configured to manage #{zfs.name}, but there is no policy configuration in zfsmgmt:policy, skipping")
|
|
315
330
|
next # zfs
|
|
316
331
|
end
|
|
317
332
|
|
|
333
|
+
snaps = zfs.snapshots
|
|
334
|
+
if snaps.empty?
|
|
335
|
+
$logger.debug("not processing #{zfs.name} as there are no snapshots")
|
|
336
|
+
next
|
|
337
|
+
end
|
|
338
|
+
|
|
318
339
|
begin
|
|
319
340
|
# call the function that decides who to save and who to delete
|
|
320
|
-
(saved,saved_snaps,deleteme) = snapshot_destroy_policy(zfs
|
|
341
|
+
(saved,saved_snaps,deleteme) = snapshot_destroy_policy(zfs)
|
|
321
342
|
rescue ArgumentError
|
|
322
|
-
$logger.error("zfs_mgmt is configured to manage #{zfs}, but there is no valid policy configuration, skipping")
|
|
343
|
+
$logger.error("zfs_mgmt is configured to manage #{zfs.name}, but there is no valid policy configuration, skipping")
|
|
323
344
|
next
|
|
324
345
|
end
|
|
325
346
|
|
|
326
|
-
$logger.info("deleting #{deleteme.length} snapshots for #{zfs}")
|
|
347
|
+
$logger.info("deleting #{deleteme.length} snapshots for #{zfs.name}")
|
|
327
348
|
deleteme.reverse! # oldest first for removal
|
|
328
349
|
deleteme.each do |snap_name|
|
|
329
350
|
$logger.debug("delete: #{snap_name} #{local_epoch_to_datetime(snaps[snap_name]['creation']).strftime('%F %T')}")
|
|
@@ -337,7 +358,7 @@ module ZfsMgmt
|
|
|
337
358
|
for i in 0..(deleteme.length - 1) do
|
|
338
359
|
max = deleteme.length - 1 - i
|
|
339
360
|
$logger.debug("attempting to remove snaps 0 through #{max} out of #{deleteme.length} snapshots")
|
|
340
|
-
bigarg = "#{zfs}@#{deleteme[0..max].map { |s| s.split('@')[1] }.join(',')}"
|
|
361
|
+
bigarg = "#{zfs.name}@#{deleteme[0..max].map { |s| s.split('@')[1] }.join(',')}"
|
|
341
362
|
com = com_base + [bigarg]
|
|
342
363
|
$logger.debug("size of bigarg: #{bigarg.length} size of com: #{com.length}")
|
|
343
364
|
if bigarg.length >= 131072 or com.length >= (2097152-10000)
|
|
@@ -369,23 +390,14 @@ module ZfsMgmt
|
|
|
369
390
|
# snapshot all filesystems configured for snapshotting
|
|
370
391
|
def self.snapshot_create(noop: false, filter: '.+')
|
|
371
392
|
dt = DateTime.now
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
)
|
|
381
|
-
}.each do |zfs,props|
|
|
382
|
-
prefix = ( props.has_key?('zfsmgmt:snap_prefix') ? props['zfsmgmt:snap_prefix'] : 'zfsmgmt' )
|
|
383
|
-
ts = ( props.has_key?('zfsmgmt:snap_timestamp') ? props['zfsmgmt:snap_timestamp'] : '%FT%T%z' )
|
|
384
|
-
com = [global_options['zfs_binary'],'snapshot']
|
|
385
|
-
if key_comp?(props,'zfsmgmt:snapshot','recursive') and key_comp?(props,'zfsmgmt:snapshot@source',['local','received'])
|
|
386
|
-
com.push('-r')
|
|
387
|
-
end
|
|
388
|
-
com.push("#{zfs}@#{[prefix,dt.strftime(ts)].join('-')}")
|
|
393
|
+
zfs_managed_list(filter: filter, property_match: { snapshot: true }).each do |zfs|
|
|
394
|
+
next unless zfs.snapshot
|
|
395
|
+
|
|
396
|
+
prefix = zfs.snap_prefix || 'zfsmgmt'
|
|
397
|
+
ts = zfs.snap_timestamp || '%FT%T%z'
|
|
398
|
+
com = [global_options['zfs_binary'] || global_options[:zfs_binary], 'snapshot']
|
|
399
|
+
com.push('-r') if zfs.snapshot_recursive
|
|
400
|
+
com.push("#{zfs.name}@#{[prefix,dt.strftime(ts)].join('-')}")
|
|
389
401
|
system_com(com,noop)
|
|
390
402
|
end
|
|
391
403
|
end
|
|
@@ -400,29 +412,31 @@ module ZfsMgmt
|
|
|
400
412
|
return $?
|
|
401
413
|
end
|
|
402
414
|
end
|
|
403
|
-
def self.zfs_send(options,zfs,props,snaps)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
destination_path = ( options[:destination] ? options[:destination] : props['zfsmgmt:destination'] )
|
|
408
|
-
if props['zfsmgmt:destination@source'] == 'local'
|
|
409
|
-
destination_path = File.join( destination_path,
|
|
410
|
-
File.basename(zfs)
|
|
411
|
-
)
|
|
412
|
-
elsif m = /inherited from (.+)/.match(props['zfsmgmt:destination@source'])
|
|
413
|
-
destination_path = File.join( destination_path,
|
|
414
|
-
File.basename(m[1]),
|
|
415
|
-
zfs.sub(m[1],'')
|
|
416
|
-
)
|
|
415
|
+
def self.zfs_send(options, zfs, props = nil, snaps = nil)
|
|
416
|
+
if zfs.is_a?(ZfsMgmt::Zfs)
|
|
417
|
+
zfs_obj = zfs
|
|
418
|
+
snaps ||= zfs_obj.snapshots
|
|
417
419
|
else
|
|
418
|
-
|
|
420
|
+
zfs_obj = ZfsMgmt::Zfs.from_zfs_props(zfs, props)
|
|
421
|
+
end
|
|
422
|
+
zfs_name = zfs_obj.name
|
|
423
|
+
sorted = snaps.keys.sort { |a,b| snaps[a]['creation'] <=> snaps[b]['creation'] }
|
|
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
|
|
431
|
+
unless destination_path
|
|
432
|
+
$logger.error("fatal error: unable to determine destination path for #{zfs_name}")
|
|
419
433
|
exit(1)
|
|
420
434
|
end
|
|
421
435
|
# does the destination zfs already exist?
|
|
422
436
|
remote_zfs_state = ''
|
|
423
437
|
begin
|
|
424
438
|
recv_zfs = zfsget(zfs: destination_path,
|
|
425
|
-
command_prefix: recv_command_prefix(options,
|
|
439
|
+
command_prefix: recv_command_prefix(options, zfs_obj),
|
|
426
440
|
#properties: ['receive_resume_token'],
|
|
427
441
|
)
|
|
428
442
|
rescue ZfsDatasetNotFoundError
|
|
@@ -445,21 +459,21 @@ module ZfsMgmt
|
|
|
445
459
|
source = sorted[0]
|
|
446
460
|
if options[:initial_snapshot] == 'newest' or
|
|
447
461
|
key_comp?(options, 'replicate') or
|
|
448
|
-
|
|
462
|
+
zfs_obj.send_replicate
|
|
449
463
|
source = sorted[-1]
|
|
450
464
|
end
|
|
451
465
|
com += zfs_send_com(options,
|
|
452
|
-
|
|
466
|
+
zfs_obj,
|
|
453
467
|
[],
|
|
454
468
|
source,
|
|
455
469
|
)
|
|
456
470
|
e = zfs_send_estimate(com) if options[:verbose] == 'pv'
|
|
457
471
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
458
472
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
459
|
-
com += zfs_recv_com(options,[],
|
|
473
|
+
com += zfs_recv_com(options,[],zfs_obj,recv_target)
|
|
460
474
|
|
|
461
475
|
status = system_com(com)
|
|
462
|
-
record_send_state(
|
|
476
|
+
record_send_state(zfs_name, status) unless options[:noop]
|
|
463
477
|
unless status && status.success?
|
|
464
478
|
return
|
|
465
479
|
end
|
|
@@ -474,10 +488,10 @@ module ZfsMgmt
|
|
|
474
488
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
475
489
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
476
490
|
|
|
477
|
-
com += zfs_recv_com(options,[],
|
|
491
|
+
com += zfs_recv_com(options,[],zfs_obj,recv_target)
|
|
478
492
|
|
|
479
493
|
status = system_com(com)
|
|
480
|
-
record_send_state(
|
|
494
|
+
record_send_state(zfs_name, status) unless options[:noop]
|
|
481
495
|
unless status && status.success?
|
|
482
496
|
return
|
|
483
497
|
end
|
|
@@ -487,7 +501,7 @@ module ZfsMgmt
|
|
|
487
501
|
begin
|
|
488
502
|
remote_snaps = zfsget(zfs: destination_path,
|
|
489
503
|
types: ['snapshot'],
|
|
490
|
-
command_prefix: recv_command_prefix(options,
|
|
504
|
+
command_prefix: recv_command_prefix(options, zfs_obj),
|
|
491
505
|
properties: ['creation','userrefs'],
|
|
492
506
|
)
|
|
493
507
|
rescue ZfsGetError
|
|
@@ -498,36 +512,34 @@ module ZfsMgmt
|
|
|
498
512
|
$logger.error("receiving filesystem has NO snapshots, it must be destroyed: #{destination_path}")
|
|
499
513
|
return
|
|
500
514
|
end
|
|
501
|
-
if remote_snaps.has_key?(sorted[-1].sub(
|
|
502
|
-
$logger.info("the most recent local snapshot (#{sorted[-1]}) already exists on the remote side (#{sorted[-1].sub(
|
|
515
|
+
if remote_snaps.has_key?(sorted[-1].sub(zfs_name,destination_path))
|
|
516
|
+
$logger.info("the most recent local snapshot (#{sorted[-1]}) already exists on the remote side (#{sorted[-1].sub(zfs_name,destination_path)})")
|
|
503
517
|
return
|
|
504
518
|
end
|
|
505
519
|
remote_snaps.sort_by { |k,v| -v['creation'] }.each do |rsnap,v|
|
|
506
520
|
# oldest first
|
|
507
|
-
|
|
508
|
-
#pp snaps
|
|
509
|
-
if snaps.has_key?(rsnap.sub(destination_path,zfs))
|
|
521
|
+
if snaps.has_key?(rsnap.sub(destination_path,zfs_name))
|
|
510
522
|
$logger.debug("process #{rsnap} to #{sorted[-1]}")
|
|
511
523
|
com = []
|
|
512
524
|
i_opt = '-i'
|
|
513
525
|
# allow the command line option for intermediary to override the property
|
|
514
526
|
if key_comp?(options,'intermediary',[true,false])
|
|
515
527
|
i_opt = '-I' if key_comp?(options, 'intermediary', true)
|
|
516
|
-
elsif
|
|
528
|
+
elsif zfs_obj.send_intermediary
|
|
517
529
|
i_opt = '-I'
|
|
518
530
|
end
|
|
519
531
|
|
|
520
|
-
com += zfs_send_com(options,
|
|
532
|
+
com += zfs_send_com(options,zfs_obj,[i_opt, dq('@' + rsnap.split('@')[1])], sorted[-1])
|
|
521
533
|
e = zfs_send_estimate(com) if options[:verbose] == 'pv'
|
|
522
534
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
523
535
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
524
|
-
com += zfs_recv_com(options,[],
|
|
536
|
+
com += zfs_recv_com(options,[],zfs_obj,recv_target)
|
|
525
537
|
|
|
526
538
|
status = system_com(com)
|
|
527
|
-
record_send_state(
|
|
539
|
+
record_send_state(zfs_name, status) unless options[:noop]
|
|
528
540
|
return
|
|
529
541
|
end
|
|
530
|
-
$logger.debug("skipping remote snapshot #{rsnap} because the same snapshot doesn't exist locally #{rsnap.sub(destination_path,
|
|
542
|
+
$logger.debug("skipping remote snapshot #{rsnap} because the same snapshot doesn't exist locally #{rsnap.sub(destination_path,zfs_name)}")
|
|
531
543
|
end
|
|
532
544
|
$logger.error("receiving filesystem has no snapshots that still exists on the sending side, it must be destroyed: #{destination_path}")
|
|
533
545
|
|
|
@@ -540,6 +552,7 @@ module ZfsMgmt
|
|
|
540
552
|
mbuffer_command
|
|
541
553
|
end
|
|
542
554
|
def self.zfs_send_com(options,props,extra_opts,target)
|
|
555
|
+
zfs_obj = props.is_a?(ZfsMgmt::Zfs) ? props : ZfsMgmt::Zfs.from_zfs_props('', props)
|
|
543
556
|
zfs_send_com = [ ZfsMgmt.global_options[:zfs_binary], 'send' ]
|
|
544
557
|
zfs_send_com.push('-v','-P') if key_comp?(options,'verbose','send')
|
|
545
558
|
send_opts = {
|
|
@@ -556,7 +569,7 @@ module ZfsMgmt
|
|
|
556
569
|
# allow the command line options to override the properties value
|
|
557
570
|
if key_comp?(options,p,[true,false])
|
|
558
571
|
zfs_send_com.push(o) if key_comp?(options,p,true)
|
|
559
|
-
elsif
|
|
572
|
+
elsif zfs_obj.public_send("send_#{p}")
|
|
560
573
|
zfs_send_com.push(o)
|
|
561
574
|
end
|
|
562
575
|
end
|
|
@@ -569,17 +582,36 @@ module ZfsMgmt
|
|
|
569
582
|
['state', :state, 'recv_state', :recv_state].each do |k|
|
|
570
583
|
return options[k] if key_comp?(options, k, [true, false])
|
|
571
584
|
end
|
|
585
|
+
return props.recv_state if props.is_a?(ZfsMgmt::Zfs)
|
|
572
586
|
return false if key_comp?(props, 'zfsmgmt:recv_state', method(:prop_off?))
|
|
573
587
|
true
|
|
574
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
|
+
|
|
575
607
|
def self.zfs_recv_com(options,extra_opts,props,target)
|
|
608
|
+
zfs_obj = props.is_a?(ZfsMgmt::Zfs) ? props : ZfsMgmt::Zfs.from_zfs_props('', props)
|
|
576
609
|
zfs_recv_com = [ ZfsMgmt.global_options[:zfs_binary], 'recv' ]
|
|
577
|
-
zfs_recv_com.push('-s') if recv_state_enabled?(options,
|
|
610
|
+
zfs_recv_com.push('-s') if recv_state_enabled?(options, zfs_obj)
|
|
578
611
|
recv_opts = {
|
|
579
612
|
'noop' => '-n',
|
|
580
613
|
'drop_holds' => '-h',
|
|
581
614
|
'unmount' => '-u',
|
|
582
|
-
'discard_last' => '-e',
|
|
583
615
|
'discard_first' => '-d',
|
|
584
616
|
'force' => '-F'
|
|
585
617
|
}
|
|
@@ -587,36 +619,37 @@ module ZfsMgmt
|
|
|
587
619
|
# allow the command line options to override the properties value
|
|
588
620
|
if key_comp?(options,p,[true,false])
|
|
589
621
|
zfs_recv_com.push(o) if key_comp?(options,p,true)
|
|
590
|
-
elsif
|
|
622
|
+
elsif zfs_obj.public_send("recv_#{p}")
|
|
591
623
|
zfs_recv_com.push(o)
|
|
592
624
|
end
|
|
593
625
|
end
|
|
594
626
|
zfs_recv_com.push('-v') if key_comp?(options, 'verbose', ['receive', 'recv'])
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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)
|
|
603
637
|
end
|
|
604
638
|
end
|
|
605
639
|
zfs_recv_com += extra_opts
|
|
606
640
|
zfs_recv_com.push(dq(target))
|
|
607
641
|
|
|
608
|
-
if options[:remote] or
|
|
642
|
+
if options[:remote] or zfs_obj.remote
|
|
609
643
|
if options[:mbuffer]
|
|
610
644
|
zfs_recv_com = mbuffer_command(options) + zfs_recv_com
|
|
611
645
|
end
|
|
612
|
-
zfs_recv_com = recv_command_prefix(options,
|
|
646
|
+
zfs_recv_com = recv_command_prefix(options, zfs_obj) + [ sq(zfs_recv_com.join(' ')) ]
|
|
613
647
|
end
|
|
614
648
|
zfs_recv_com
|
|
615
649
|
end
|
|
616
650
|
def self.recv_command_prefix(options,props)
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
[] )
|
|
651
|
+
remote = options[:remote] || (props.is_a?(ZfsMgmt::Zfs) ? props.remote : props['zfsmgmt:remote'])
|
|
652
|
+
remote ? [ 'ssh', remote ] : []
|
|
620
653
|
end
|
|
621
654
|
def self.zfs_send_estimate(com)
|
|
622
655
|
lcom = com.dup
|
|
@@ -663,22 +696,25 @@ module ZfsMgmt
|
|
|
663
696
|
def self.match_filter?(zfs, filter)
|
|
664
697
|
/#{filter}/ =~ zfs
|
|
665
698
|
end
|
|
666
|
-
def self.
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
return
|
|
671
|
-
elsif
|
|
672
|
-
return
|
|
673
|
-
elsif
|
|
674
|
-
return
|
|
675
|
-
elsif v.kind_of?(Regexp)
|
|
676
|
-
return v =~ h[p]
|
|
699
|
+
def self.match_value?(actual, expected)
|
|
700
|
+
if expected.kind_of?(Array)
|
|
701
|
+
return expected.include?(actual)
|
|
702
|
+
elsif expected.kind_of?(Hash)
|
|
703
|
+
return expected.keys.include?(actual)
|
|
704
|
+
elsif expected.kind_of?(Method) || expected.kind_of?(Proc)
|
|
705
|
+
return expected.call(actual)
|
|
706
|
+
elsif expected.kind_of?(Regexp)
|
|
707
|
+
return expected =~ actual
|
|
677
708
|
else
|
|
678
709
|
# string, boolean, numbers?
|
|
679
|
-
return
|
|
710
|
+
return actual == expected
|
|
680
711
|
end
|
|
681
712
|
end
|
|
713
|
+
def self.key_comp?(h,p,v = method(:prop_on?))
|
|
714
|
+
#$logger.debug("p:#{p}\th[p]:#{h[p]}\tv:#{v}")
|
|
715
|
+
return false unless h.has_key?(p)
|
|
716
|
+
match_value?(h[p], v)
|
|
717
|
+
end
|
|
682
718
|
def self.set_log_level(sev = nil)
|
|
683
719
|
sev = ENV['ZFS_MGMT_LOGLEVEL'] if sev.nil? || sev.to_s.strip.empty?
|
|
684
720
|
return if sev.nil? || sev.to_s.strip.empty?
|
|
@@ -702,21 +738,20 @@ module ZfsMgmt
|
|
|
702
738
|
set_log_level
|
|
703
739
|
def self.zfs_send_all(options)
|
|
704
740
|
zfs_managed_list(filter: options[:filter],
|
|
705
|
-
property_match: {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
$logger.debug("skipping received filesystem: #{zfs}")
|
|
741
|
+
property_match: { send_enabled: true }).each do |zfs|
|
|
742
|
+
unless zfs.send_enabled
|
|
743
|
+
$logger.debug("skipping filesystem with send disabled: #{zfs.name}")
|
|
709
744
|
next
|
|
710
745
|
end
|
|
711
|
-
|
|
712
|
-
$logger.
|
|
746
|
+
unless zfs.destination
|
|
747
|
+
$logger.error("#{zfs.name}: you must specify a destination zfs path via the user property zfsmgmt:destination, even if using --destination on the command line, skipping")
|
|
713
748
|
next
|
|
714
749
|
end
|
|
715
|
-
|
|
716
|
-
$logger.
|
|
750
|
+
if zfs.snapshots.empty?
|
|
751
|
+
$logger.debug("not processing #{zfs.name} as there are no snapshots")
|
|
717
752
|
next
|
|
718
753
|
end
|
|
719
|
-
zfs_send(options,zfs
|
|
754
|
+
zfs_send(options, zfs)
|
|
720
755
|
end
|
|
721
756
|
end
|
|
722
757
|
def self.lock(options)
|
data/zfs_mgmt.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zfs_mgmt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aran Cox
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -122,16 +121,29 @@ dependencies:
|
|
|
122
121
|
- - ">="
|
|
123
122
|
- !ruby/object:Gem::Version
|
|
124
123
|
version: '0'
|
|
125
|
-
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: easy_talk
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
type: :runtime
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
126
138
|
email:
|
|
127
139
|
- arancox@gmail.com
|
|
128
140
|
executables:
|
|
129
141
|
- readsnaps
|
|
130
|
-
- zfssendman
|
|
131
|
-
- zfssnapman
|
|
132
|
-
- zfsrecvman
|
|
133
142
|
- zfs-list-snapshots
|
|
134
143
|
- zfsmgr
|
|
144
|
+
- zfsrecvman
|
|
145
|
+
- zfssendman
|
|
146
|
+
- zfssnapman
|
|
135
147
|
extensions: []
|
|
136
148
|
extra_rdoc_files: []
|
|
137
149
|
files:
|
|
@@ -159,6 +171,7 @@ files:
|
|
|
159
171
|
- lib/zfs_mgmt.rb
|
|
160
172
|
- lib/zfs_mgmt/restic.rb
|
|
161
173
|
- lib/zfs_mgmt/version.rb
|
|
174
|
+
- lib/zfs_mgmt/zfs.rb
|
|
162
175
|
- lib/zfs_mgmt/zfs_mgr.rb
|
|
163
176
|
- lib/zfs_mgmt/zfs_mgr/list.rb
|
|
164
177
|
- lib/zfs_mgmt/zfs_mgr/restic.rb
|
|
@@ -173,7 +186,6 @@ metadata:
|
|
|
173
186
|
homepage_uri: https://github.com/aranc23/zfs_mgmt
|
|
174
187
|
source_code_uri: https://github.com/aranc23/zfs_mgmt
|
|
175
188
|
changelog_uri: https://github.com/aranc23/zfs_mgmt/commits/
|
|
176
|
-
post_install_message:
|
|
177
189
|
rdoc_options: []
|
|
178
190
|
require_paths:
|
|
179
191
|
- lib
|
|
@@ -188,8 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
188
200
|
- !ruby/object:Gem::Version
|
|
189
201
|
version: '0'
|
|
190
202
|
requirements: []
|
|
191
|
-
rubygems_version: 3.
|
|
192
|
-
signing_key:
|
|
203
|
+
rubygems_version: 3.6.9
|
|
193
204
|
specification_version: 4
|
|
194
205
|
summary: Misc. helpers regarding snapshots and send/recv.
|
|
195
206
|
test_files: []
|