zfs_mgmt 0.5.6 → 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/.github/workflows/rspec.yml +20 -0
- data/AGENTS.md +35 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +56 -1
- data/bin/zfsmgr +4 -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/zfs_mgr/send.rb +33 -0
- data/lib/zfs_mgmt/zfs_mgr/snapshot.rb +3 -1
- data/lib/zfs_mgmt.rb +273 -139
- data/zfs_mgmt.gemspec +3 -0
- metadata +46 -1
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
|
|
@@ -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,25 +1,66 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
zfs_mgmt (0.
|
|
4
|
+
zfs_mgmt (0.6.1)
|
|
5
|
+
easy_talk
|
|
5
6
|
filesize (~> 0.2)
|
|
7
|
+
pstore
|
|
6
8
|
text-table (~> 1.2)
|
|
7
9
|
thor (~> 1.0)
|
|
8
10
|
|
|
9
11
|
GEM
|
|
10
12
|
remote: https://rubygems.org/
|
|
11
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)
|
|
12
34
|
diff-lcs (1.6.2)
|
|
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)
|
|
13
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)
|
|
14
49
|
json (3.1.0)
|
|
15
50
|
language_server-protocol (3.17.0.6)
|
|
16
51
|
logger (1.7.0)
|
|
52
|
+
minitest (6.1.0)
|
|
53
|
+
drb (~> 2.0)
|
|
54
|
+
prism (>= 1.5, < 3)
|
|
17
55
|
prism (1.9.0)
|
|
56
|
+
pstore (0.2.1)
|
|
18
57
|
rake (13.4.2)
|
|
19
58
|
rbs (4.2.0)
|
|
20
59
|
logger
|
|
21
60
|
prism (>= 1.6.0)
|
|
22
61
|
tsort
|
|
62
|
+
regexp_parser (2.13.4)
|
|
63
|
+
regexp_property_values (1.5.2)
|
|
23
64
|
rspec (3.13.2)
|
|
24
65
|
rspec-core (~> 3.13.0)
|
|
25
66
|
rspec-expectations (~> 3.13.0)
|
|
@@ -37,21 +78,35 @@ GEM
|
|
|
37
78
|
language_server-protocol (~> 3.17.0)
|
|
38
79
|
prism (>= 1.2, < 2.0)
|
|
39
80
|
rbs (>= 3, < 5)
|
|
81
|
+
securerandom (0.4.1)
|
|
82
|
+
simplecov (0.22.0)
|
|
83
|
+
docile (~> 1.1)
|
|
84
|
+
simplecov-html (~> 0.11)
|
|
85
|
+
simplecov_json_formatter (~> 0.1)
|
|
86
|
+
simplecov-html (0.13.2)
|
|
87
|
+
simplecov_json_formatter (0.1.4)
|
|
88
|
+
sorbet-runtime (0.6.13715)
|
|
40
89
|
text-table (1.2.4)
|
|
41
90
|
thor (1.5.0)
|
|
42
91
|
timeout (0.6.1)
|
|
43
92
|
tsort (0.2.0)
|
|
93
|
+
tzinfo (2.0.6)
|
|
94
|
+
concurrent-ruby (~> 1.0)
|
|
95
|
+
uri (1.1.2)
|
|
44
96
|
|
|
45
97
|
PLATFORMS
|
|
46
98
|
x86_64-linux
|
|
47
99
|
|
|
48
100
|
DEPENDENCIES
|
|
49
101
|
bundler (>= 2.2.33)
|
|
102
|
+
easy_talk
|
|
50
103
|
filesize
|
|
51
104
|
json
|
|
105
|
+
pstore
|
|
52
106
|
rake (>= 12.3.3)
|
|
53
107
|
rspec (~> 3.0)
|
|
54
108
|
ruby-lsp
|
|
109
|
+
simplecov (~> 0.22)
|
|
55
110
|
text-table
|
|
56
111
|
thor
|
|
57
112
|
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/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(',')]
|
|
@@ -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,
|