zfs_mgmt 0.6.0 → 0.6.1
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/Gemfile +1 -0
- data/Gemfile.lock +46 -2
- data/lib/zfs_mgmt/restic.rb +10 -7
- data/lib/zfs_mgmt/version.rb +1 -1
- data/lib/zfs_mgmt/zfs.rb +242 -0
- data/lib/zfs_mgmt/zfs_mgr/list.rb +7 -3
- data/lib/zfs_mgmt.rb +128 -118
- 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: b257ace0d8d1392c232a62c63bba999eda3b692b17d29ad5db6ed5ce99d5b348
|
|
4
|
+
data.tar.gz: 40d44012ed1641358989ff2ff1a8f2bf333d5fb7cc4fdddb89f26d4aa0c1fcb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ff464d3d77c6205859a7b8eb20756371bf593d286f385cddc58bcd53f057f07193014825231e5e5db9e9c6ce6f67a6f6eb990eb176df7c1e643bc8f05eb0674
|
|
7
|
+
data.tar.gz: c0c774813a8d759e5be301c633c0f02c106921ed8a40d1212e627a3e45219e3656993565fb9ec9aa4571023658f4dd4a9334ac03f479fe6c65717325ae53b89c
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
zfs_mgmt (0.6.
|
|
4
|
+
zfs_mgmt (0.6.1)
|
|
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/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,242 @@
|
|
|
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_last
|
|
24
|
+
recv_discard_first
|
|
25
|
+
recv_force
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
define_schema do
|
|
29
|
+
title 'Zfs'
|
|
30
|
+
description 'Encapsulates zfsmgmt:* user properties for a ZFS dataset'
|
|
31
|
+
|
|
32
|
+
property :name, String,
|
|
33
|
+
description: 'Full name of the ZFS dataset (e.g. tank/data)'
|
|
34
|
+
|
|
35
|
+
# Snapshot retention policy properties
|
|
36
|
+
property :manage, T::Boolean, optional: true, default: false,
|
|
37
|
+
description: 'Whether snapshot retention management is enabled for this dataset'
|
|
38
|
+
property :policy, String, optional: true, pattern: '\A(\d+[hdwmyHDWMY])+\z',
|
|
39
|
+
description: 'Snapshot retention policy specification (e.g. 10y60m104w365d168h)'
|
|
40
|
+
property :strategy, String, optional: true, enum: %w[oldest youngest], default: 'oldest',
|
|
41
|
+
description: 'Which snapshot to retain within each policy timeframe'
|
|
42
|
+
property :minage, String, optional: true, pattern: '\A\d+[smhdwSMHDW]?\z',
|
|
43
|
+
description: 'Minimum age before a snapshot is eligible for destruction (e.g. 7D)'
|
|
44
|
+
property :matchsnaps, String, optional: true,
|
|
45
|
+
description: 'Regular expression that snapshot names must match to satisfy retention policy'
|
|
46
|
+
property :ignoresnaps, String, optional: true,
|
|
47
|
+
description: 'Regular expression for snapshot names to ignore during policy evaluation and destruction'
|
|
48
|
+
property :prefersnaps, String, optional: true,
|
|
49
|
+
description: 'Regular expression for snapshot names preferred when selecting snapshots to retain'
|
|
50
|
+
|
|
51
|
+
# Snapshot creation properties
|
|
52
|
+
property :snapshot, T::Boolean, optional: true, default: false,
|
|
53
|
+
description: 'Whether snapshots should be created for this dataset'
|
|
54
|
+
property :snapshot_recursive, T::Boolean, optional: true, default: false,
|
|
55
|
+
description: 'Whether snapshots should be created recursively (-r) for this dataset'
|
|
56
|
+
property :snap_prefix, String, optional: true, default: 'zfsmgmt',
|
|
57
|
+
description: 'Prefix used when naming created snapshots'
|
|
58
|
+
property :snap_timestamp, String, optional: true, default: '%FT%T%z',
|
|
59
|
+
description: 'strftime format string used when naming created snapshots'
|
|
60
|
+
|
|
61
|
+
# ZFS send/recv properties
|
|
62
|
+
property :send_enabled, T::Boolean, optional: true, default: false, as: :send,
|
|
63
|
+
description: 'Whether zfs send is enabled for this dataset'
|
|
64
|
+
property :remote, String, optional: true,
|
|
65
|
+
description: 'Remote SSH target for zfs recv (e.g. user@host)'
|
|
66
|
+
property :destination, String, optional: true,
|
|
67
|
+
description: 'Resolved destination ZFS dataset path for zfs send/recv'
|
|
68
|
+
|
|
69
|
+
property :send_intermediary, T::Boolean, optional: true, default: false,
|
|
70
|
+
description: 'Pass -I (intermediary snapshots) to zfs send'
|
|
71
|
+
property :send_backup, T::Boolean, optional: true, default: false,
|
|
72
|
+
description: 'Pass -b (backup) to zfs send'
|
|
73
|
+
property :send_compressed, T::Boolean, optional: true, default: false,
|
|
74
|
+
description: 'Pass -c (compressed) to zfs send'
|
|
75
|
+
property :send_embed, T::Boolean, optional: true, default: false,
|
|
76
|
+
description: 'Pass -e (embed) to zfs send'
|
|
77
|
+
property :send_holds, T::Boolean, optional: true, default: false,
|
|
78
|
+
description: 'Pass -h (holds) to zfs send'
|
|
79
|
+
property :send_large_block, T::Boolean, optional: true, default: false,
|
|
80
|
+
description: 'Pass -L (large block) to zfs send'
|
|
81
|
+
property :send_props, T::Boolean, optional: true, default: false,
|
|
82
|
+
description: 'Pass -p (properties) to zfs send'
|
|
83
|
+
property :send_raw, T::Boolean, optional: true, default: false,
|
|
84
|
+
description: 'Pass -w (raw) to zfs send'
|
|
85
|
+
property :send_replicate, T::Boolean, optional: true, default: false,
|
|
86
|
+
description: 'Pass -R (replicate) to zfs send'
|
|
87
|
+
|
|
88
|
+
property :recv_state, T::Boolean, optional: true, default: true,
|
|
89
|
+
description: 'Pass -s (save partial receive state) to zfs recv'
|
|
90
|
+
property :recv_noop, T::Boolean, optional: true, default: false,
|
|
91
|
+
description: 'Pass -n (noop) to zfs recv'
|
|
92
|
+
property :recv_drop_holds, T::Boolean, optional: true, default: false,
|
|
93
|
+
description: 'Pass -h (drop holds) to zfs recv'
|
|
94
|
+
property :recv_unmount, T::Boolean, optional: true, default: false,
|
|
95
|
+
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
|
+
property :recv_discard_first, T::Boolean, optional: true, default: false,
|
|
99
|
+
description: 'Pass -d (discard first path element) to zfs recv'
|
|
100
|
+
property :recv_force, T::Boolean, optional: true, default: false,
|
|
101
|
+
description: 'Pass -F (force rollback) to zfs recv'
|
|
102
|
+
|
|
103
|
+
# Restic backup properties
|
|
104
|
+
property :restic_backup, T::Boolean, optional: true, default: false,
|
|
105
|
+
description: 'Whether restic backup is enabled for this dataset'
|
|
106
|
+
property :restic_repository, String, optional: true,
|
|
107
|
+
description: 'Target restic repository for backups'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def initialize(attributes = {})
|
|
111
|
+
attrs = attributes.transform_keys(&:to_sym)
|
|
112
|
+
@snapshots = attrs.delete(:snapshots) if attrs.key?(:snapshots)
|
|
113
|
+
@destination_relative_path = attrs.delete(:destination_relative_path) if attrs.key?(:destination_relative_path)
|
|
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 snapshots
|
|
129
|
+
return @snapshots unless @snapshots.nil?
|
|
130
|
+
|
|
131
|
+
@snapshots = ZfsMgmt.zfsget(
|
|
132
|
+
properties: %w[name creation userrefs used written referenced],
|
|
133
|
+
types: ['snapshot'],
|
|
134
|
+
zfs: name
|
|
135
|
+
)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def snapshots=(value)
|
|
139
|
+
@snapshots = value
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def snapshots_loaded?
|
|
143
|
+
!@snapshots.nil?
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def reload_snapshots!
|
|
147
|
+
@snapshots = nil
|
|
148
|
+
snapshots
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def resolved_destination(override = nil)
|
|
152
|
+
return destination unless override
|
|
153
|
+
|
|
154
|
+
rel = @destination_relative_path || File.basename(name)
|
|
155
|
+
File.join(override, rel)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def self.from_zfs_props(name, props = {})
|
|
159
|
+
props ||= {}
|
|
160
|
+
attrs = { name: name }
|
|
161
|
+
|
|
162
|
+
attrs[:manage] = ZfsMgmt.prop_on?(props['zfsmgmt:manage'])
|
|
163
|
+
attrs[:policy] = props['zfsmgmt:policy'] if props.key?('zfsmgmt:policy')
|
|
164
|
+
attrs[:strategy] = props['zfsmgmt:strategy'] if props.key?('zfsmgmt:strategy')
|
|
165
|
+
attrs[:minage] = props['zfsmgmt:minage'] if props.key?('zfsmgmt:minage')
|
|
166
|
+
attrs[:matchsnaps] = props['zfsmgmt:matchsnaps'] if props.key?('zfsmgmt:matchsnaps')
|
|
167
|
+
attrs[:ignoresnaps] = props['zfsmgmt:ignoresnaps'] if props.key?('zfsmgmt:ignoresnaps')
|
|
168
|
+
attrs[:prefersnaps] = props['zfsmgmt:prefersnaps'] if props.key?('zfsmgmt:prefersnaps')
|
|
169
|
+
|
|
170
|
+
# Interpret zfsmgmt:snapshot taking its @source into account
|
|
171
|
+
snap_val = props['zfsmgmt:snapshot']
|
|
172
|
+
snap_src = props['zfsmgmt:snapshot@source']
|
|
173
|
+
if ZfsMgmt.prop_on?(snap_val)
|
|
174
|
+
attrs[:snapshot] = true
|
|
175
|
+
attrs[:snapshot_recursive] = false
|
|
176
|
+
elsif %w[recursive local].include?(snap_val) && %w[local received].include?(snap_src)
|
|
177
|
+
attrs[:snapshot] = true
|
|
178
|
+
attrs[:snapshot_recursive] = (snap_val == 'recursive')
|
|
179
|
+
else
|
|
180
|
+
attrs[:snapshot] = false
|
|
181
|
+
attrs[:snapshot_recursive] = false
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
attrs[:snap_prefix] = props['zfsmgmt:snap_prefix'] if props.key?('zfsmgmt:snap_prefix')
|
|
185
|
+
attrs[:snap_timestamp] = props['zfsmgmt:snap_timestamp'] if props.key?('zfsmgmt:snap_timestamp')
|
|
186
|
+
|
|
187
|
+
# Interpret zfsmgmt:send and zfsmgmt:send_replicate taking @source into account
|
|
188
|
+
send_val = props['zfsmgmt:send']
|
|
189
|
+
send_src = props['zfsmgmt:send@source']
|
|
190
|
+
rep_val = props['zfsmgmt:send_replicate']
|
|
191
|
+
rep_src = props['zfsmgmt:send_replicate@source']
|
|
192
|
+
|
|
193
|
+
replicated_descendant = ZfsMgmt.prop_on?(rep_val) && !rep_src.nil? && rep_src != 'local'
|
|
194
|
+
attrs[:send_replicate] = ZfsMgmt.prop_on?(rep_val) && !replicated_descendant
|
|
195
|
+
|
|
196
|
+
attrs[:send_enabled] =
|
|
197
|
+
if send_src == 'received' || replicated_descendant
|
|
198
|
+
false
|
|
199
|
+
elsif ZfsMgmt.prop_on?(send_val)
|
|
200
|
+
true
|
|
201
|
+
elsif send_val == 'local' && send_src == 'local'
|
|
202
|
+
true
|
|
203
|
+
else
|
|
204
|
+
false
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
attrs[:remote] = props['zfsmgmt:remote'] if props.key?('zfsmgmt:remote')
|
|
208
|
+
|
|
209
|
+
# Interpret zfsmgmt:destination taking @source into account
|
|
210
|
+
if props.key?('zfsmgmt:destination')
|
|
211
|
+
dest_base = props['zfsmgmt:destination']
|
|
212
|
+
dest_src = props['zfsmgmt:destination@source']
|
|
213
|
+
if dest_src == 'local'
|
|
214
|
+
rel = File.basename(name)
|
|
215
|
+
attrs[:destination] = File.join(dest_base, rel)
|
|
216
|
+
attrs[:destination_relative_path] = rel
|
|
217
|
+
elsif dest_src && (m = /\Ainherited from (.+)\z/.match(dest_src))
|
|
218
|
+
rel = File.join(File.basename(m[1]), name.sub(m[1], ''))
|
|
219
|
+
attrs[:destination] = File.join(dest_base, rel)
|
|
220
|
+
attrs[:destination_relative_path] = rel
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
SEND_BOOL_PROPS.each do |prop|
|
|
225
|
+
key = "zfsmgmt:#{prop}"
|
|
226
|
+
attrs[prop] = ZfsMgmt.prop_on?(props[key]) if props.key?(key)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
attrs[:recv_state] = !ZfsMgmt.prop_off?(props['zfsmgmt:recv_state']) if props.key?('zfsmgmt:recv_state')
|
|
230
|
+
|
|
231
|
+
RECV_BOOL_PROPS.each do |prop|
|
|
232
|
+
key = "zfsmgmt:#{prop}"
|
|
233
|
+
attrs[prop] = ZfsMgmt.prop_on?(props[key]) if props.key?(key)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
attrs[:restic_backup] = ZfsMgmt.prop_on?(props['zfsmgmt:restic_backup']) if props.key?('zfsmgmt:restic_backup')
|
|
237
|
+
attrs[:restic_repository] = props['zfsmgmt:restic_repository'] if props.key?('zfsmgmt:restic_repository')
|
|
238
|
+
|
|
239
|
+
new(attrs)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
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(',')]
|
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,25 @@ 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
|
+
destination_path = zfs_obj.resolved_destination(options[:destination])
|
|
425
|
+
unless destination_path
|
|
426
|
+
$logger.error("fatal error: unable to determine destination path for #{zfs_name}")
|
|
419
427
|
exit(1)
|
|
420
428
|
end
|
|
421
429
|
# does the destination zfs already exist?
|
|
422
430
|
remote_zfs_state = ''
|
|
423
431
|
begin
|
|
424
432
|
recv_zfs = zfsget(zfs: destination_path,
|
|
425
|
-
command_prefix: recv_command_prefix(options,
|
|
433
|
+
command_prefix: recv_command_prefix(options, zfs_obj),
|
|
426
434
|
#properties: ['receive_resume_token'],
|
|
427
435
|
)
|
|
428
436
|
rescue ZfsDatasetNotFoundError
|
|
@@ -445,21 +453,21 @@ module ZfsMgmt
|
|
|
445
453
|
source = sorted[0]
|
|
446
454
|
if options[:initial_snapshot] == 'newest' or
|
|
447
455
|
key_comp?(options, 'replicate') or
|
|
448
|
-
|
|
456
|
+
zfs_obj.send_replicate
|
|
449
457
|
source = sorted[-1]
|
|
450
458
|
end
|
|
451
459
|
com += zfs_send_com(options,
|
|
452
|
-
|
|
460
|
+
zfs_obj,
|
|
453
461
|
[],
|
|
454
462
|
source,
|
|
455
463
|
)
|
|
456
464
|
e = zfs_send_estimate(com) if options[:verbose] == 'pv'
|
|
457
465
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
458
466
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
459
|
-
com += zfs_recv_com(options,[],
|
|
467
|
+
com += zfs_recv_com(options,[],zfs_obj,destination_path)
|
|
460
468
|
|
|
461
469
|
status = system_com(com)
|
|
462
|
-
record_send_state(
|
|
470
|
+
record_send_state(zfs_name, status) unless options[:noop]
|
|
463
471
|
unless status && status.success?
|
|
464
472
|
return
|
|
465
473
|
end
|
|
@@ -474,10 +482,10 @@ module ZfsMgmt
|
|
|
474
482
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
475
483
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
476
484
|
|
|
477
|
-
com += zfs_recv_com(options,[],
|
|
485
|
+
com += zfs_recv_com(options,[],zfs_obj,destination_path)
|
|
478
486
|
|
|
479
487
|
status = system_com(com)
|
|
480
|
-
record_send_state(
|
|
488
|
+
record_send_state(zfs_name, status) unless options[:noop]
|
|
481
489
|
unless status && status.success?
|
|
482
490
|
return
|
|
483
491
|
end
|
|
@@ -487,7 +495,7 @@ module ZfsMgmt
|
|
|
487
495
|
begin
|
|
488
496
|
remote_snaps = zfsget(zfs: destination_path,
|
|
489
497
|
types: ['snapshot'],
|
|
490
|
-
command_prefix: recv_command_prefix(options,
|
|
498
|
+
command_prefix: recv_command_prefix(options, zfs_obj),
|
|
491
499
|
properties: ['creation','userrefs'],
|
|
492
500
|
)
|
|
493
501
|
rescue ZfsGetError
|
|
@@ -498,36 +506,34 @@ module ZfsMgmt
|
|
|
498
506
|
$logger.error("receiving filesystem has NO snapshots, it must be destroyed: #{destination_path}")
|
|
499
507
|
return
|
|
500
508
|
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(
|
|
509
|
+
if remote_snaps.has_key?(sorted[-1].sub(zfs_name,destination_path))
|
|
510
|
+
$logger.info("the most recent local snapshot (#{sorted[-1]}) already exists on the remote side (#{sorted[-1].sub(zfs_name,destination_path)})")
|
|
503
511
|
return
|
|
504
512
|
end
|
|
505
513
|
remote_snaps.sort_by { |k,v| -v['creation'] }.each do |rsnap,v|
|
|
506
514
|
# oldest first
|
|
507
|
-
|
|
508
|
-
#pp snaps
|
|
509
|
-
if snaps.has_key?(rsnap.sub(destination_path,zfs))
|
|
515
|
+
if snaps.has_key?(rsnap.sub(destination_path,zfs_name))
|
|
510
516
|
$logger.debug("process #{rsnap} to #{sorted[-1]}")
|
|
511
517
|
com = []
|
|
512
518
|
i_opt = '-i'
|
|
513
519
|
# allow the command line option for intermediary to override the property
|
|
514
520
|
if key_comp?(options,'intermediary',[true,false])
|
|
515
521
|
i_opt = '-I' if key_comp?(options, 'intermediary', true)
|
|
516
|
-
elsif
|
|
522
|
+
elsif zfs_obj.send_intermediary
|
|
517
523
|
i_opt = '-I'
|
|
518
524
|
end
|
|
519
525
|
|
|
520
|
-
com += zfs_send_com(options,
|
|
526
|
+
com += zfs_send_com(options,zfs_obj,[i_opt, dq('@' + rsnap.split('@')[1])], sorted[-1])
|
|
521
527
|
e = zfs_send_estimate(com) if options[:verbose] == 'pv'
|
|
522
528
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
523
529
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
524
|
-
com += zfs_recv_com(options,[],
|
|
530
|
+
com += zfs_recv_com(options,[],zfs_obj,destination_path)
|
|
525
531
|
|
|
526
532
|
status = system_com(com)
|
|
527
|
-
record_send_state(
|
|
533
|
+
record_send_state(zfs_name, status) unless options[:noop]
|
|
528
534
|
return
|
|
529
535
|
end
|
|
530
|
-
$logger.debug("skipping remote snapshot #{rsnap} because the same snapshot doesn't exist locally #{rsnap.sub(destination_path,
|
|
536
|
+
$logger.debug("skipping remote snapshot #{rsnap} because the same snapshot doesn't exist locally #{rsnap.sub(destination_path,zfs_name)}")
|
|
531
537
|
end
|
|
532
538
|
$logger.error("receiving filesystem has no snapshots that still exists on the sending side, it must be destroyed: #{destination_path}")
|
|
533
539
|
|
|
@@ -540,6 +546,7 @@ module ZfsMgmt
|
|
|
540
546
|
mbuffer_command
|
|
541
547
|
end
|
|
542
548
|
def self.zfs_send_com(options,props,extra_opts,target)
|
|
549
|
+
zfs_obj = props.is_a?(ZfsMgmt::Zfs) ? props : ZfsMgmt::Zfs.from_zfs_props('', props)
|
|
543
550
|
zfs_send_com = [ ZfsMgmt.global_options[:zfs_binary], 'send' ]
|
|
544
551
|
zfs_send_com.push('-v','-P') if key_comp?(options,'verbose','send')
|
|
545
552
|
send_opts = {
|
|
@@ -556,7 +563,7 @@ module ZfsMgmt
|
|
|
556
563
|
# allow the command line options to override the properties value
|
|
557
564
|
if key_comp?(options,p,[true,false])
|
|
558
565
|
zfs_send_com.push(o) if key_comp?(options,p,true)
|
|
559
|
-
elsif
|
|
566
|
+
elsif zfs_obj.public_send("send_#{p}")
|
|
560
567
|
zfs_send_com.push(o)
|
|
561
568
|
end
|
|
562
569
|
end
|
|
@@ -569,12 +576,14 @@ module ZfsMgmt
|
|
|
569
576
|
['state', :state, 'recv_state', :recv_state].each do |k|
|
|
570
577
|
return options[k] if key_comp?(options, k, [true, false])
|
|
571
578
|
end
|
|
579
|
+
return props.recv_state if props.is_a?(ZfsMgmt::Zfs)
|
|
572
580
|
return false if key_comp?(props, 'zfsmgmt:recv_state', method(:prop_off?))
|
|
573
581
|
true
|
|
574
582
|
end
|
|
575
583
|
def self.zfs_recv_com(options,extra_opts,props,target)
|
|
584
|
+
zfs_obj = props.is_a?(ZfsMgmt::Zfs) ? props : ZfsMgmt::Zfs.from_zfs_props('', props)
|
|
576
585
|
zfs_recv_com = [ ZfsMgmt.global_options[:zfs_binary], 'recv' ]
|
|
577
|
-
zfs_recv_com.push('-s') if recv_state_enabled?(options,
|
|
586
|
+
zfs_recv_com.push('-s') if recv_state_enabled?(options, zfs_obj)
|
|
578
587
|
recv_opts = {
|
|
579
588
|
'noop' => '-n',
|
|
580
589
|
'drop_holds' => '-h',
|
|
@@ -587,7 +596,7 @@ module ZfsMgmt
|
|
|
587
596
|
# allow the command line options to override the properties value
|
|
588
597
|
if key_comp?(options,p,[true,false])
|
|
589
598
|
zfs_recv_com.push(o) if key_comp?(options,p,true)
|
|
590
|
-
elsif
|
|
599
|
+
elsif zfs_obj.public_send("recv_#{p}")
|
|
591
600
|
zfs_recv_com.push(o)
|
|
592
601
|
end
|
|
593
602
|
end
|
|
@@ -605,18 +614,17 @@ module ZfsMgmt
|
|
|
605
614
|
zfs_recv_com += extra_opts
|
|
606
615
|
zfs_recv_com.push(dq(target))
|
|
607
616
|
|
|
608
|
-
if options[:remote] or
|
|
617
|
+
if options[:remote] or zfs_obj.remote
|
|
609
618
|
if options[:mbuffer]
|
|
610
619
|
zfs_recv_com = mbuffer_command(options) + zfs_recv_com
|
|
611
620
|
end
|
|
612
|
-
zfs_recv_com = recv_command_prefix(options,
|
|
621
|
+
zfs_recv_com = recv_command_prefix(options, zfs_obj) + [ sq(zfs_recv_com.join(' ')) ]
|
|
613
622
|
end
|
|
614
623
|
zfs_recv_com
|
|
615
624
|
end
|
|
616
625
|
def self.recv_command_prefix(options,props)
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
[] )
|
|
626
|
+
remote = options[:remote] || (props.is_a?(ZfsMgmt::Zfs) ? props.remote : props['zfsmgmt:remote'])
|
|
627
|
+
remote ? [ 'ssh', remote ] : []
|
|
620
628
|
end
|
|
621
629
|
def self.zfs_send_estimate(com)
|
|
622
630
|
lcom = com.dup
|
|
@@ -663,22 +671,25 @@ module ZfsMgmt
|
|
|
663
671
|
def self.match_filter?(zfs, filter)
|
|
664
672
|
/#{filter}/ =~ zfs
|
|
665
673
|
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]
|
|
674
|
+
def self.match_value?(actual, expected)
|
|
675
|
+
if expected.kind_of?(Array)
|
|
676
|
+
return expected.include?(actual)
|
|
677
|
+
elsif expected.kind_of?(Hash)
|
|
678
|
+
return expected.keys.include?(actual)
|
|
679
|
+
elsif expected.kind_of?(Method) || expected.kind_of?(Proc)
|
|
680
|
+
return expected.call(actual)
|
|
681
|
+
elsif expected.kind_of?(Regexp)
|
|
682
|
+
return expected =~ actual
|
|
677
683
|
else
|
|
678
684
|
# string, boolean, numbers?
|
|
679
|
-
return
|
|
685
|
+
return actual == expected
|
|
680
686
|
end
|
|
681
687
|
end
|
|
688
|
+
def self.key_comp?(h,p,v = method(:prop_on?))
|
|
689
|
+
#$logger.debug("p:#{p}\th[p]:#{h[p]}\tv:#{v}")
|
|
690
|
+
return false unless h.has_key?(p)
|
|
691
|
+
match_value?(h[p], v)
|
|
692
|
+
end
|
|
682
693
|
def self.set_log_level(sev = nil)
|
|
683
694
|
sev = ENV['ZFS_MGMT_LOGLEVEL'] if sev.nil? || sev.to_s.strip.empty?
|
|
684
695
|
return if sev.nil? || sev.to_s.strip.empty?
|
|
@@ -702,21 +713,20 @@ module ZfsMgmt
|
|
|
702
713
|
set_log_level
|
|
703
714
|
def self.zfs_send_all(options)
|
|
704
715
|
zfs_managed_list(filter: options[:filter],
|
|
705
|
-
property_match: {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
$logger.debug("skipping received filesystem: #{zfs}")
|
|
716
|
+
property_match: { send_enabled: true }).each do |zfs|
|
|
717
|
+
unless zfs.send_enabled
|
|
718
|
+
$logger.debug("skipping filesystem with send disabled: #{zfs.name}")
|
|
709
719
|
next
|
|
710
720
|
end
|
|
711
|
-
|
|
712
|
-
$logger.
|
|
721
|
+
unless zfs.destination
|
|
722
|
+
$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
723
|
next
|
|
714
724
|
end
|
|
715
|
-
|
|
716
|
-
$logger.
|
|
725
|
+
if zfs.snapshots.empty?
|
|
726
|
+
$logger.debug("not processing #{zfs.name} as there are no snapshots")
|
|
717
727
|
next
|
|
718
728
|
end
|
|
719
|
-
zfs_send(options,zfs
|
|
729
|
+
zfs_send(options, zfs)
|
|
720
730
|
end
|
|
721
731
|
end
|
|
722
732
|
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.6.
|
|
4
|
+
version: 0.6.1
|
|
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: []
|