zfs_mgmt 0.5.6 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +20 -0
- data/AGENTS.md +35 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +13 -2
- data/bin/zfsmgr +4 -2
- data/lib/zfs_mgmt/version.rb +1 -1
- data/lib/zfs_mgmt/zfs_mgr/send.rb +33 -0
- data/lib/zfs_mgmt/zfs_mgr/snapshot.rb +3 -1
- data/lib/zfs_mgmt.rb +150 -26
- data/zfs_mgmt.gemspec +2 -0
- metadata +40 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 819f2bd2081c228ce173f3960dc37489e28203f91f48d927f3ade7d8e056e297
|
|
4
|
+
data.tar.gz: 192323a67ffc72db76ce2328e98774546e1e598db0269b3ef1ac73d765e34402
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4cd51b0b79580af548be7d84e893856e5db7be234a9bf6c571c9f71715b6e7312d69dce58c1efbe02ceb61fba51f0ef6277c22b1c23ba6d89d18cd5c69ed8d8
|
|
7
|
+
data.tar.gz: e023322f391fbae157e6779d860b2ad5467393a344cf17061cfbd37eefa5a8a38828177025c45be00cd4f50c6396473eafa99d7d53e670e2e01c702200c7562a
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: RSpec
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
rspec:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v5
|
|
14
|
+
|
|
15
|
+
- uses: ruby/setup-ruby@v1
|
|
16
|
+
with:
|
|
17
|
+
bundler-cache: true
|
|
18
|
+
|
|
19
|
+
- name: Run RSpec
|
|
20
|
+
run: bundle exec rspec
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
### Github Issue Workflow
|
|
3
|
+
|
|
4
|
+
When asked to resolve a Github issue:
|
|
5
|
+
|
|
6
|
+
1. **Inspect Issue (MCP):**
|
|
7
|
+
* Fetch issue details using the `Github` MCP server before starting work to confirm requirements and acceptance criteria.
|
|
8
|
+
|
|
9
|
+
2. **Branch & Implement (Local Shell):**
|
|
10
|
+
* Use the local terminal/git CLI to branch from the default branch:
|
|
11
|
+
```bash
|
|
12
|
+
git checkout -b <type>/issue-<id>-<slug>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
*(Use `fix/` for bug fixes, `feat/` for features/enhancements).*
|
|
17
|
+
* Make edits locally, run required test suites and linters, and commit changes using standard git commits.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
3. **Push to Remote (Local Shell via SSH/Git):**
|
|
21
|
+
* Do **not** attempt to push commits via MCP. Push directly using the local git tool:
|
|
22
|
+
```bash
|
|
23
|
+
git push -u origin <branch-name>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
4. **Create Pull Request (MCP):**
|
|
27
|
+
* Open the Pull Request using the `Github` MCP server's pull request creation tool.
|
|
28
|
+
* Include `Resolves #<id>` in the PR description to trigger Github's automatic issue closing on merge.
|
|
29
|
+
* Capture the resulting PR number and URL.
|
|
30
|
+
|
|
31
|
+
5. **Update Issue Thread (MCP):**
|
|
32
|
+
* Post a comment on the original issue using `create_issue_comment` detailing:
|
|
33
|
+
* The branch name pushed.
|
|
34
|
+
* Summary of key architectural or code changes made.
|
|
35
|
+
* Link and reference to the created Pull Request.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
zfs_mgmt (0.
|
|
4
|
+
zfs_mgmt (0.6.0)
|
|
5
5
|
filesize (~> 0.2)
|
|
6
|
+
pstore
|
|
6
7
|
text-table (~> 1.2)
|
|
7
8
|
thor (~> 1.0)
|
|
8
9
|
|
|
@@ -10,13 +11,15 @@ GEM
|
|
|
10
11
|
remote: https://rubygems.org/
|
|
11
12
|
specs:
|
|
12
13
|
diff-lcs (1.6.2)
|
|
14
|
+
docile (1.4.1)
|
|
13
15
|
filesize (0.2.0)
|
|
14
16
|
json (3.1.0)
|
|
15
17
|
language_server-protocol (3.17.0.6)
|
|
16
18
|
logger (1.7.0)
|
|
17
19
|
prism (1.9.0)
|
|
20
|
+
pstore (0.2.1)
|
|
18
21
|
rake (13.4.2)
|
|
19
|
-
rbs (4.
|
|
22
|
+
rbs (4.1.3)
|
|
20
23
|
logger
|
|
21
24
|
prism (>= 1.6.0)
|
|
22
25
|
tsort
|
|
@@ -37,6 +40,12 @@ GEM
|
|
|
37
40
|
language_server-protocol (~> 3.17.0)
|
|
38
41
|
prism (>= 1.2, < 2.0)
|
|
39
42
|
rbs (>= 3, < 5)
|
|
43
|
+
simplecov (0.22.0)
|
|
44
|
+
docile (~> 1.1)
|
|
45
|
+
simplecov-html (~> 0.11)
|
|
46
|
+
simplecov_json_formatter (~> 0.1)
|
|
47
|
+
simplecov-html (0.13.2)
|
|
48
|
+
simplecov_json_formatter (0.1.4)
|
|
40
49
|
text-table (1.2.4)
|
|
41
50
|
thor (1.5.0)
|
|
42
51
|
timeout (0.6.1)
|
|
@@ -49,9 +58,11 @@ DEPENDENCIES
|
|
|
49
58
|
bundler (>= 2.2.33)
|
|
50
59
|
filesize
|
|
51
60
|
json
|
|
61
|
+
pstore
|
|
52
62
|
rake (>= 12.3.3)
|
|
53
63
|
rspec (~> 3.0)
|
|
54
64
|
ruby-lsp
|
|
65
|
+
simplecov (~> 0.22)
|
|
55
66
|
text-table
|
|
56
67
|
thor
|
|
57
68
|
timeout
|
data/bin/zfsmgr
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
1
2
|
require "thor"
|
|
2
3
|
require "zfs_mgmt"
|
|
3
4
|
require "zfs_mgmt/restic"
|
|
@@ -13,8 +14,9 @@ class ZfsMgr < Thor
|
|
|
13
14
|
:desc => 'mbuffer binary'
|
|
14
15
|
class_option :pv_binary, :type => :string, :default => 'pv',
|
|
15
16
|
:desc => 'pv binary'
|
|
16
|
-
class_option :loglevel, :type => :string,
|
|
17
|
-
:
|
|
17
|
+
class_option :loglevel, :type => :string,
|
|
18
|
+
:default => ( (ENV['ZFS_MGMT_LOGLEVEL'] && !ENV['ZFS_MGMT_LOGLEVEL'].empty?) ? ENV['ZFS_MGMT_LOGLEVEL'].downcase : ( $stdout.isatty ? 'info' : 'warn' ) ),
|
|
19
|
+
:enum => ['debug','error','fatal','info','warn','unknown'],
|
|
18
20
|
:desc => 'set logging level to specified severity'
|
|
19
21
|
class_option :lock, :type => :boolean, :default => false,
|
|
20
22
|
:desc => 'lock before running'
|
data/lib/zfs_mgmt/version.rb
CHANGED
|
@@ -31,6 +31,7 @@ class ZfsMgmt::ZfsMgr::Send < Thor
|
|
|
31
31
|
method_option :drop_holds, :desc => "pass the -h option to zfs recv, indicating holds should be ignored", :type => :boolean
|
|
32
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
33
|
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
|
+
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
|
|
34
35
|
|
|
35
36
|
method_option :mbuffer, :desc => "insert mbuffer between send and recv", :default => true, :type => :boolean
|
|
36
37
|
method_option :mbuffer_size, :desc => "passed to mbuffer -s option", :type => :string
|
|
@@ -42,4 +43,36 @@ class ZfsMgmt::ZfsMgr::Send < Thor
|
|
|
42
43
|
ZfsMgmt.zfs_send_all(options)
|
|
43
44
|
ZfsMgmt.unlock(lock)
|
|
44
45
|
end
|
|
46
|
+
|
|
47
|
+
class State < Thor
|
|
48
|
+
class_option :filter, :type => :string, :default => '.+',
|
|
49
|
+
:desc => 'only act on zfs matching this regexp'
|
|
50
|
+
default_command :show
|
|
51
|
+
|
|
52
|
+
desc "show", "print a table of the values in the state db"
|
|
53
|
+
method_option :check, :type => :boolean, :default => false,
|
|
54
|
+
:desc => 'print a check_mk local style check output, one line for each entry in the db'
|
|
55
|
+
def show()
|
|
56
|
+
ZfsMgmt.set_log_level(options[:loglevel])
|
|
57
|
+
ZfsMgmt.global_options = options
|
|
58
|
+
ZfsMgmt.send_state_show(check: options[:check], filter: options[:filter])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
desc "delete ZFS", "delete a key from the state db"
|
|
62
|
+
def delete(zfs)
|
|
63
|
+
ZfsMgmt.set_log_level(options[:loglevel])
|
|
64
|
+
ZfsMgmt.global_options = options
|
|
65
|
+
ZfsMgmt.send_state_delete(zfs)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc "wipe", "remove all keys in state db"
|
|
69
|
+
def wipe()
|
|
70
|
+
ZfsMgmt.set_log_level(options[:loglevel])
|
|
71
|
+
ZfsMgmt.global_options = options
|
|
72
|
+
ZfsMgmt.send_state_wipe
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
desc "state [SUBCOMMAND ...ARGS]", "manage zfs send state database"
|
|
77
|
+
subcommand "state", State
|
|
45
78
|
end
|
|
@@ -16,10 +16,12 @@ class ZfsMgmt::ZfsMgr::Snapshot < Thor
|
|
|
16
16
|
ZfsMgmt.unlock(lock)
|
|
17
17
|
end
|
|
18
18
|
desc "policy", "print the policy table for zfs"
|
|
19
|
+
method_option :show_destroy, :type => :boolean, :default => false,
|
|
20
|
+
:desc => 'interleave snapshots that would be deleted with kept snapshots'
|
|
19
21
|
def policy()
|
|
20
22
|
ZfsMgmt.set_log_level(options[:loglevel])
|
|
21
23
|
ZfsMgmt.global_options = options
|
|
22
|
-
ZfsMgmt.snapshot_policy(filter: options[:filter])
|
|
24
|
+
ZfsMgmt.snapshot_policy(filter: options[:filter], show_destroy: options[:show_destroy])
|
|
23
25
|
end
|
|
24
26
|
desc "create", "execute zfs snapshot based on zfs properties"
|
|
25
27
|
method_option :noop, :type => :boolean, :default => false,
|
data/lib/zfs_mgmt.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
require "zfs_mgmt/version"
|
|
3
|
+
require "thor"
|
|
3
4
|
require "zfs_mgmt/restic"
|
|
4
5
|
require "zfs_mgmt/zfs_mgr"
|
|
5
6
|
require 'pp'
|
|
@@ -9,6 +10,9 @@ require 'text-table'
|
|
|
9
10
|
require 'open3'
|
|
10
11
|
require 'filesize'
|
|
11
12
|
require 'timeout'
|
|
13
|
+
require 'pstore'
|
|
14
|
+
require 'json'
|
|
15
|
+
require 'fileutils'
|
|
12
16
|
|
|
13
17
|
$logger = Logger.new(STDERR, progname: 'zfs_mgmt')
|
|
14
18
|
|
|
@@ -46,6 +50,8 @@ module ZfsMgmt
|
|
|
46
50
|
end
|
|
47
51
|
class ZfsGetError < StandardError
|
|
48
52
|
end
|
|
53
|
+
class ZfsDatasetNotFoundError < ZfsGetError
|
|
54
|
+
end
|
|
49
55
|
def self.custom_properties()
|
|
50
56
|
return [
|
|
51
57
|
'policy',
|
|
@@ -61,6 +67,7 @@ module ZfsMgmt
|
|
|
61
67
|
'send',
|
|
62
68
|
'remote',
|
|
63
69
|
'destination',
|
|
70
|
+
'recv_state',
|
|
64
71
|
].map do |p|
|
|
65
72
|
['zfsmgmt',p].join(':')
|
|
66
73
|
end
|
|
@@ -123,6 +130,12 @@ module ZfsMgmt
|
|
|
123
130
|
raise ZfsGetError, "process was signalled \"#{com.join(' ')}\", termsig #{status.termsig}"
|
|
124
131
|
end
|
|
125
132
|
unless status.success?
|
|
133
|
+
if se =~ /cannot open '.*': dataset does not exist/i || se =~ /dataset does not exist/i
|
|
134
|
+
$logger.debug("dataset does not exist when running \"#{com.join(' ')}\", exit status #{status.exitstatus}")
|
|
135
|
+
so.split("\n").each { |l| $logger.debug("stdout: #{l}") }
|
|
136
|
+
se.split("\n").each { |l| $logger.debug("stderr: #{l}") }
|
|
137
|
+
raise ZfsDatasetNotFoundError, "dataset does not exist: #{zfs}"
|
|
138
|
+
end
|
|
126
139
|
$logger.error("failed to execute \"#{com.join(' ')}\", exit status #{status.exitstatus}")
|
|
127
140
|
so.split("\n").each { |l| $logger.debug("stdout: #{l}") }
|
|
128
141
|
se.split("\n").each { |l| $logger.error("stderr: #{l}") }
|
|
@@ -264,7 +277,7 @@ module ZfsMgmt
|
|
|
264
277
|
end
|
|
265
278
|
return zfss
|
|
266
279
|
end
|
|
267
|
-
def self.snapshot_policy(filter: '.+')
|
|
280
|
+
def self.snapshot_policy(filter: '.+', show_destroy: false)
|
|
268
281
|
zfs_managed_list(filter: filter).each do |zfs,props,snaps|
|
|
269
282
|
unless props.has_key?('zfsmgmt:policy')
|
|
270
283
|
$logger.error("zfs_mgmt is configured to manage #{zfs}, but there is no policy configuration in zfsmgmt:policy, skipping")
|
|
@@ -279,7 +292,9 @@ module ZfsMgmt
|
|
|
279
292
|
next
|
|
280
293
|
end
|
|
281
294
|
|
|
282
|
-
|
|
295
|
+
snaps_to_show = show_destroy ? (saved_snaps + deleteme).uniq : saved_snaps
|
|
296
|
+
|
|
297
|
+
if snaps_to_show.length == 0
|
|
283
298
|
$logger.info("no snapshots marked as saved by policy for #{zfs}")
|
|
284
299
|
next
|
|
285
300
|
end
|
|
@@ -287,7 +302,7 @@ module ZfsMgmt
|
|
|
287
302
|
table = Text::Table.new
|
|
288
303
|
table.head = [zfs,'creation','hourly','daily','weekly','monthly','yearly']
|
|
289
304
|
table.rows = []
|
|
290
|
-
|
|
305
|
+
snaps_to_show.sort { |a,b| snaps[b]['creation'] <=> snaps[a]['creation'] }.each do |snap|
|
|
291
306
|
table.rows << [snap.split('@')[1],local_epoch_to_datetime(snaps[snap]['creation'])] + find_saved_reason(saved,snap)
|
|
292
307
|
end
|
|
293
308
|
print table.to_s
|
|
@@ -382,6 +397,7 @@ module ZfsMgmt
|
|
|
382
397
|
unless $?.success?
|
|
383
398
|
$logger.error("command failed: #{$?.exitstatus}")
|
|
384
399
|
end
|
|
400
|
+
return $?
|
|
385
401
|
end
|
|
386
402
|
end
|
|
387
403
|
def self.zfs_send(options,zfs,props,snaps)
|
|
@@ -409,9 +425,12 @@ module ZfsMgmt
|
|
|
409
425
|
command_prefix: recv_command_prefix(options,props),
|
|
410
426
|
#properties: ['receive_resume_token'],
|
|
411
427
|
)
|
|
412
|
-
rescue
|
|
428
|
+
rescue ZfsDatasetNotFoundError
|
|
413
429
|
$logger.debug("recv filesystem doesn't exist: #{destination_path}")
|
|
414
430
|
remote_zfs_state = 'missing'
|
|
431
|
+
rescue ZfsGetError
|
|
432
|
+
$logger.error("unable to check remote filesystem #{destination_path}")
|
|
433
|
+
return
|
|
415
434
|
else
|
|
416
435
|
if recv_zfs[destination_path].has_key?('receive_resume_token')
|
|
417
436
|
remote_zfs_state = recv_zfs[destination_path]['receive_resume_token']
|
|
@@ -439,8 +458,9 @@ module ZfsMgmt
|
|
|
439
458
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
440
459
|
com += zfs_recv_com(options,[],props,destination_path)
|
|
441
460
|
|
|
442
|
-
system_com(com)
|
|
443
|
-
unless
|
|
461
|
+
status = system_com(com)
|
|
462
|
+
record_send_state(zfs, status) unless options[:noop]
|
|
463
|
+
unless status && status.success?
|
|
444
464
|
return
|
|
445
465
|
end
|
|
446
466
|
|
|
@@ -454,23 +474,11 @@ module ZfsMgmt
|
|
|
454
474
|
com += mbuffer_command(options) if options[:mbuffer]
|
|
455
475
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
456
476
|
|
|
457
|
-
|
|
458
|
-
recv.push('-n') if options[:noop]
|
|
459
|
-
recv.push('-u') if options[:unmount]
|
|
460
|
-
recv.push('-v') if options[:verbose] and ( options[:verbose] == 'receive' or options[:verbose] == 'recv' )
|
|
461
|
-
recv.push(dq(destination_path))
|
|
462
|
-
|
|
463
|
-
if options[:remote] or props['zfsmgmt:remote']
|
|
464
|
-
if options[:mbuffer]
|
|
465
|
-
recv = mbuffer_command(options) + recv
|
|
466
|
-
end
|
|
467
|
-
recv = recv_command_prefix(options,props) + [ sq(recv.join(' ')) ]
|
|
468
|
-
end
|
|
469
|
-
|
|
470
|
-
com += recv
|
|
477
|
+
com += zfs_recv_com(options,[],props,destination_path)
|
|
471
478
|
|
|
472
|
-
system_com(com)
|
|
473
|
-
unless
|
|
479
|
+
status = system_com(com)
|
|
480
|
+
record_send_state(zfs, status) unless options[:noop]
|
|
481
|
+
unless status && status.success?
|
|
474
482
|
return
|
|
475
483
|
end
|
|
476
484
|
end
|
|
@@ -515,7 +523,8 @@ module ZfsMgmt
|
|
|
515
523
|
com += pv_command(options,e) if options[:verbose] == 'pv'
|
|
516
524
|
com += zfs_recv_com(options,[],props,destination_path)
|
|
517
525
|
|
|
518
|
-
system_com(com)
|
|
526
|
+
status = system_com(com)
|
|
527
|
+
record_send_state(zfs, status) unless options[:noop]
|
|
519
528
|
return
|
|
520
529
|
end
|
|
521
530
|
$logger.debug("skipping remote snapshot #{rsnap} because the same snapshot doesn't exist locally #{rsnap.sub(destination_path,zfs)}")
|
|
@@ -553,8 +562,19 @@ module ZfsMgmt
|
|
|
553
562
|
end
|
|
554
563
|
zfs_send_com + extra_opts + [dq(target),'|']
|
|
555
564
|
end
|
|
565
|
+
def self.prop_off?(v)
|
|
566
|
+
['false','off'].include?(v)
|
|
567
|
+
end
|
|
568
|
+
def self.recv_state_enabled?(options, props)
|
|
569
|
+
['state', :state, 'recv_state', :recv_state].each do |k|
|
|
570
|
+
return options[k] if key_comp?(options, k, [true, false])
|
|
571
|
+
end
|
|
572
|
+
return false if key_comp?(props, 'zfsmgmt:recv_state', method(:prop_off?))
|
|
573
|
+
true
|
|
574
|
+
end
|
|
556
575
|
def self.zfs_recv_com(options,extra_opts,props,target)
|
|
557
|
-
zfs_recv_com = [ ZfsMgmt.global_options[:zfs_binary], 'recv'
|
|
576
|
+
zfs_recv_com = [ ZfsMgmt.global_options[:zfs_binary], 'recv' ]
|
|
577
|
+
zfs_recv_com.push('-s') if recv_state_enabled?(options, props)
|
|
558
578
|
recv_opts = {
|
|
559
579
|
'noop' => '-n',
|
|
560
580
|
'drop_holds' => '-h',
|
|
@@ -659,8 +679,10 @@ module ZfsMgmt
|
|
|
659
679
|
return h[p] == v
|
|
660
680
|
end
|
|
661
681
|
end
|
|
662
|
-
def self.set_log_level(sev)
|
|
663
|
-
|
|
682
|
+
def self.set_log_level(sev = nil)
|
|
683
|
+
sev = ENV['ZFS_MGMT_LOGLEVEL'] if sev.nil? || sev.to_s.strip.empty?
|
|
684
|
+
return if sev.nil? || sev.to_s.strip.empty?
|
|
685
|
+
case sev.to_s.strip.downcase
|
|
664
686
|
when 'debug'
|
|
665
687
|
$logger.level = Logger::DEBUG
|
|
666
688
|
when 'info'
|
|
@@ -671,8 +693,13 @@ module ZfsMgmt
|
|
|
671
693
|
$logger.level = Logger::ERROR
|
|
672
694
|
when 'fatal'
|
|
673
695
|
$logger.level = Logger::FATAL
|
|
696
|
+
when 'unknown', 'off', 'none', 'silent'
|
|
697
|
+
$logger.level = Logger::UNKNOWN
|
|
698
|
+
when /\A\d+\z/
|
|
699
|
+
$logger.level = sev.to_i
|
|
674
700
|
end
|
|
675
701
|
end
|
|
702
|
+
set_log_level
|
|
676
703
|
def self.zfs_send_all(options)
|
|
677
704
|
zfs_managed_list(filter: options[:filter],
|
|
678
705
|
property_match: { 'zfsmgmt:send' => method(:prop_on?) }).each do |zfs,props,snaps|
|
|
@@ -735,4 +762,101 @@ module ZfsMgmt
|
|
|
735
762
|
lock.close()
|
|
736
763
|
end
|
|
737
764
|
end
|
|
765
|
+
|
|
766
|
+
SEND_WARN_SECONDS = 36 * 60 * 60
|
|
767
|
+
SEND_CRIT_SECONDS = 72 * 60 * 60
|
|
768
|
+
|
|
769
|
+
def self.send_state_db_path
|
|
770
|
+
if global_options && global_options[:state_db]
|
|
771
|
+
return global_options[:state_db]
|
|
772
|
+
end
|
|
773
|
+
dir = if Process.euid == 0
|
|
774
|
+
'/var/lib/zfs_mgmt'
|
|
775
|
+
elsif ENV['XDG_STATE_HOME'] && !ENV['XDG_STATE_HOME'].empty?
|
|
776
|
+
File.join(ENV['XDG_STATE_HOME'], 'zfs_mgmt')
|
|
777
|
+
else
|
|
778
|
+
File.join(Dir.home, '.local', 'state', 'zfs_mgmt')
|
|
779
|
+
end
|
|
780
|
+
File.join(dir, 'send_state.pstore')
|
|
781
|
+
end
|
|
782
|
+
|
|
783
|
+
def self.send_state_store(path = send_state_db_path)
|
|
784
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
785
|
+
PStore.new(path)
|
|
786
|
+
end
|
|
787
|
+
|
|
788
|
+
def self.record_send_state(zfs, status, timestamp: Time.now.to_i)
|
|
789
|
+
exit_code = if status.nil?
|
|
790
|
+
1
|
|
791
|
+
elsif status.respond_to?(:exitstatus)
|
|
792
|
+
status.exitstatus || (status.respond_to?(:termsig) && status.termsig ? 128 + status.termsig : 1)
|
|
793
|
+
else
|
|
794
|
+
status.to_i
|
|
795
|
+
end
|
|
796
|
+
store = send_state_store
|
|
797
|
+
store.transaction do
|
|
798
|
+
store[zfs] = JSON.generate({ 'timestamp' => timestamp.to_i, 'exit' => exit_code })
|
|
799
|
+
end
|
|
800
|
+
end
|
|
801
|
+
|
|
802
|
+
def self.send_state_entries(filter: '.+')
|
|
803
|
+
path = send_state_db_path
|
|
804
|
+
return {} unless File.exist?(path)
|
|
805
|
+
store = send_state_store(path)
|
|
806
|
+
entries = {}
|
|
807
|
+
store.transaction(true) do
|
|
808
|
+
store.roots.sort.each do |zfs|
|
|
809
|
+
next unless match_filter?(zfs, filter)
|
|
810
|
+
raw = store[zfs]
|
|
811
|
+
data = raw.is_a?(String) ? JSON.parse(raw) : raw
|
|
812
|
+
entries[zfs] = data
|
|
813
|
+
end
|
|
814
|
+
end
|
|
815
|
+
entries
|
|
816
|
+
end
|
|
817
|
+
|
|
818
|
+
def self.send_state_delete(zfs)
|
|
819
|
+
store = send_state_store
|
|
820
|
+
store.transaction do
|
|
821
|
+
store.delete(zfs)
|
|
822
|
+
end
|
|
823
|
+
end
|
|
824
|
+
|
|
825
|
+
def self.send_state_wipe
|
|
826
|
+
store = send_state_store
|
|
827
|
+
store.transaction do
|
|
828
|
+
store.roots.each do |k|
|
|
829
|
+
store.delete(k)
|
|
830
|
+
end
|
|
831
|
+
end
|
|
832
|
+
end
|
|
833
|
+
|
|
834
|
+
def self.send_state_show(check: false, filter: '.+')
|
|
835
|
+
entries = send_state_entries(filter: filter)
|
|
836
|
+
if check
|
|
837
|
+
now = Time.now.to_i
|
|
838
|
+
entries.each do |zfs, data|
|
|
839
|
+
ts = data['timestamp'].to_i
|
|
840
|
+
exit_code = data['exit'].to_i
|
|
841
|
+
age = [now - ts, 0].max
|
|
842
|
+
time_str = local_epoch_to_datetime(ts).to_s
|
|
843
|
+
state = if exit_code != 0 || age > SEND_CRIT_SECONDS
|
|
844
|
+
2
|
|
845
|
+
elsif age > SEND_WARN_SECONDS
|
|
846
|
+
1
|
|
847
|
+
else
|
|
848
|
+
0
|
|
849
|
+
end
|
|
850
|
+
puts "#{state} \"zfs_send #{zfs}\" age=#{age};#{SEND_WARN_SECONDS};#{SEND_CRIT_SECONDS} last send #{time_str} exit #{exit_code}"
|
|
851
|
+
end
|
|
852
|
+
else
|
|
853
|
+
return if entries.empty?
|
|
854
|
+
table = Text::Table.new
|
|
855
|
+
table.head = ['zfs', 'timestamp', 'exit']
|
|
856
|
+
table.rows = entries.map do |zfs, data|
|
|
857
|
+
[zfs, local_epoch_to_datetime(data['timestamp'].to_i), data['exit']]
|
|
858
|
+
end
|
|
859
|
+
print table.to_s
|
|
860
|
+
end
|
|
861
|
+
end
|
|
738
862
|
end
|
data/zfs_mgmt.gemspec
CHANGED
|
@@ -39,8 +39,10 @@ Gem::Specification.new do |spec|
|
|
|
39
39
|
spec.add_development_dependency "bundler", ">= 2.2.33"
|
|
40
40
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
|
41
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
42
|
+
spec.add_development_dependency "simplecov", "~> 0.22"
|
|
42
43
|
spec.add_runtime_dependency "thor", "~> 1.0"
|
|
43
44
|
spec.add_runtime_dependency "text-table", "~> 1.2"
|
|
44
45
|
spec.add_runtime_dependency "filesize", "~> 0.2"
|
|
46
|
+
spec.add_runtime_dependency "pstore"
|
|
45
47
|
|
|
46
48
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zfs_mgmt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aran Cox
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-11-19 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: bundler
|
|
@@ -51,6 +52,20 @@ dependencies:
|
|
|
51
52
|
- - "~>"
|
|
52
53
|
- !ruby/object:Gem::Version
|
|
53
54
|
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: simplecov
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.22'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.22'
|
|
54
69
|
- !ruby/object:Gem::Dependency
|
|
55
70
|
name: thor
|
|
56
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -93,23 +108,40 @@ dependencies:
|
|
|
93
108
|
- - "~>"
|
|
94
109
|
- !ruby/object:Gem::Version
|
|
95
110
|
version: '0.2'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: pstore
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
description:
|
|
96
126
|
email:
|
|
97
127
|
- arancox@gmail.com
|
|
98
128
|
executables:
|
|
99
129
|
- readsnaps
|
|
100
|
-
- zfs-list-snapshots
|
|
101
|
-
- zfsmgr
|
|
102
|
-
- zfsrecvman
|
|
103
130
|
- zfssendman
|
|
104
131
|
- zfssnapman
|
|
132
|
+
- zfsrecvman
|
|
133
|
+
- zfs-list-snapshots
|
|
134
|
+
- zfsmgr
|
|
105
135
|
extensions: []
|
|
106
136
|
extra_rdoc_files: []
|
|
107
137
|
files:
|
|
138
|
+
- ".github/workflows/rspec.yml"
|
|
108
139
|
- ".gitignore"
|
|
109
140
|
- ".rspec"
|
|
110
141
|
- ".ruby-version"
|
|
111
142
|
- ".solargraph.yml"
|
|
112
143
|
- ".travis.yml"
|
|
144
|
+
- AGENTS.md
|
|
113
145
|
- COPYING
|
|
114
146
|
- Gemfile
|
|
115
147
|
- Gemfile.lock
|
|
@@ -141,6 +173,7 @@ metadata:
|
|
|
141
173
|
homepage_uri: https://github.com/aranc23/zfs_mgmt
|
|
142
174
|
source_code_uri: https://github.com/aranc23/zfs_mgmt
|
|
143
175
|
changelog_uri: https://github.com/aranc23/zfs_mgmt/commits/
|
|
176
|
+
post_install_message:
|
|
144
177
|
rdoc_options: []
|
|
145
178
|
require_paths:
|
|
146
179
|
- lib
|
|
@@ -155,7 +188,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
155
188
|
- !ruby/object:Gem::Version
|
|
156
189
|
version: '0'
|
|
157
190
|
requirements: []
|
|
158
|
-
rubygems_version: 3.
|
|
191
|
+
rubygems_version: 3.4.1
|
|
192
|
+
signing_key:
|
|
159
193
|
specification_version: 4
|
|
160
194
|
summary: Misc. helpers regarding snapshots and send/recv.
|
|
161
195
|
test_files: []
|