zfs_mgmt 0.4.6 → 0.4.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1022834076fa1482f627f9c5b7f8a476dd3e83d3358495d40f6695b23e842a88
4
- data.tar.gz: ddc4f5f6e87c00f5cb0c0adbe2b4ddc47f78670c520b701d359b471b19c081c4
3
+ metadata.gz: a7f44dfd817cadcabaf53c1b8fcfd251b59ffcd919aa8a97a6cc9d19c98bbf45
4
+ data.tar.gz: 01b9855f993dac35e65e8d41bf67552bd50c85d18d7e6929c6aa8d564dd9533b
5
5
  SHA512:
6
- metadata.gz: 06eab68af755becb316e438c5e027e78166952c7a37dc1c32343193f140e0a12463784b6a42ada068c0a90571641a11c7971143349d0dff6cc1a2581f34cbe9b
7
- data.tar.gz: 9fa676ecf9837096a5e97649f01dfa398610898019f4abd0694fee241e75733767193898e26e618516c23cbf394dcdf1bdb8d9c4639a70a77d49db5b34c2ede4
6
+ metadata.gz: c9eb6b8de6cc72dec2445ccd4b937c9655fb8ac10105991c9351fe31afd138c5a66575797dcb746a9f0da176cb8c57aeffcc25a8a9ba32fc59f835d2a0b5381e
7
+ data.tar.gz: c65977164b6aa98cfc3112ef9a9cdb767d7dc675e0bc4acbe2e118becb35b11d8eb6a8b9bf818959cb3754f6b492471481fbde155e966364f21f02a79c983943
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ gem "thor"
7
7
  gem "text-table"
8
8
  gem "filesize"
9
9
  gem "json"
10
+ gem "timeout"
10
11
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zfs_mgmt (0.4.6)
4
+ zfs_mgmt (0.4.8)
5
5
  filesize (~> 0.2)
6
6
  text-table (~> 1.2)
7
7
  thor (~> 1.0)
@@ -28,6 +28,7 @@ GEM
28
28
  rspec-support (3.11.0)
29
29
  text-table (1.2.4)
30
30
  thor (1.2.1)
31
+ timeout (0.4.1)
31
32
 
32
33
  PLATFORMS
33
34
  x86_64-linux
@@ -40,6 +41,7 @@ DEPENDENCIES
40
41
  rspec (~> 3.0)
41
42
  text-table
42
43
  thor
44
+ timeout
43
45
  zfs_mgmt!
44
46
 
45
47
  BUNDLED WITH
data/README.md CHANGED
@@ -4,8 +4,8 @@ zfs_mgmt aims to provide some useful helpers for managing zfs
4
4
  snapshots, and eventually send/recv duties via the zfsmgr script in
5
5
  bin/.
6
6
 
7
- Currently only snapshot destruction is implemented by a policy
8
- specification stored in zfs properties.
7
+ Snapshot creation and deletion by policy along with zfs send wrapping
8
+ are implementation by specifications stored in zfs properties.
9
9
 
10
10
  ## Installation
11
11
 
data/bin/zfsmgr CHANGED
@@ -16,6 +16,12 @@ class ZfsMgr < Thor
16
16
  class_option :loglevel, :type => :string, :default => ( $stdout.isatty ? 'info' : 'warn' ),
17
17
  :enum => ['debug','error','fatal','info','warn'],
18
18
  :desc => 'set logging level to specified severity'
19
+ class_option :lock, :type => :boolean, :default => false,
20
+ :desc => 'lock before running'
21
+ class_option :lock_file, :type => :string, :default => '/run/zfsmgr.lock',
22
+ :desc => 'lock file'
23
+ class_option :lock_wait, :type => :numeric, :default => 0,
24
+ :desc => 'wait N seconds for lock'
19
25
  desc "zfsget [ZFS]", "execute zfs get for the given properties and types and parse the output into a nested hash"
20
26
  method_option :properties, :type => :string, :default => ['name'], :desc => "List of properties passed to zfs get", repeatable: true
21
27
  method_option :types, :type => :array, :default => ['filesystem','volume'], enum: ['filesystem','volume','snapshot'], :desc => "list of types"
@@ -1,3 +1,3 @@
1
1
  module ZfsMgmt
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.8"
3
3
  end
@@ -34,7 +34,9 @@ class ZfsMgmt::ZfsMgr::Send < Thor
34
34
  def all()
35
35
  ZfsMgmt.set_log_level(options[:loglevel])
36
36
  ZfsMgmt.global_options = options
37
+ lock = ZfsMgmt.lock(options)
37
38
 
38
39
  ZfsMgmt.zfs_send_all(options)
40
+ ZfsMgmt.unlock(lock)
39
41
  end
40
42
  end
@@ -11,7 +11,9 @@ class ZfsMgmt::ZfsMgr::Snapshot < Thor
11
11
  def destroy()
12
12
  ZfsMgmt.set_log_level(options[:loglevel])
13
13
  ZfsMgmt.global_options = options
14
+ lock = ZfsMgmt.lock(options)
14
15
  ZfsMgmt.snapshot_destroy(noop: options[:noop], verbose: options[:verbose], filter: options[:filter])
16
+ ZfsMgmt.unlock(lock)
15
17
  end
16
18
  desc "policy", "print the policy table for zfs"
17
19
  def policy()
@@ -25,6 +27,7 @@ class ZfsMgmt::ZfsMgr::Snapshot < Thor
25
27
  def create()
26
28
  ZfsMgmt.set_log_level(options[:loglevel])
27
29
  ZfsMgmt.global_options = options
30
+ lock = ZfsMgmt.lock(options)
28
31
  ZfsMgmt.snapshot_create(noop: options[:noop], filter: options[:filter])
29
32
  end
30
33
  end
data/lib/zfs_mgmt.rb CHANGED
@@ -8,6 +8,7 @@ require 'logger'
8
8
  require 'text-table'
9
9
  require 'open3'
10
10
  require 'filesize'
11
+ require 'timeout'
11
12
 
12
13
  $logger = Logger.new(STDERR, progname: 'zfs_mgmt')
13
14
 
@@ -37,6 +38,8 @@ $properties_xlate = {
37
38
  'creation' => ->(x) { x.to_i },
38
39
  }
39
40
 
41
+ $lock = nil
42
+
40
43
  module ZfsMgmt
41
44
  class << self
42
45
  attr_accessor :global_options
@@ -603,11 +606,17 @@ module ZfsMgmt
603
606
  lcom.push('2>&1')
604
607
  lcom = precom + lcom
605
608
  $logger.debug(lcom.join(' '))
609
+ total = 0
606
610
  %x[#{lcom.join(' ')}].each_line do |l|
607
- if m = /(incremental|size).*\s+(\d+)$/.match(l)
608
- return m[2].to_i
611
+ if m = /^size\s+(\d+)$/.match(l)
612
+ return m[1].to_i
613
+ elsif m = /^incremental\s+.+?\s+.+?\s+(\d+)$/.match(l)
614
+ total = total + m[1].to_i
609
615
  end
610
616
  end
617
+ if total > 0
618
+ return total
619
+ end
611
620
  $logger.error("no estimate available")
612
621
  return nil
613
622
  end
@@ -682,4 +691,40 @@ module ZfsMgmt
682
691
  zfs_send(options,zfs,props,snaps)
683
692
  end
684
693
  end
694
+ def self.lock(options)
695
+ # open lock file, try to lock file until lock_wait has expired or
696
+ # lock is obtained, write pid?
697
+ return nil unless options[:lock]
698
+ begin
699
+ lock = File.open(options[:lock_file], File::RDWR|File::CREAT, 0644)
700
+ rescue Errno::ENOENT => error
701
+ $logger.error("unable to open lock file (#{options[:lock_file]}), possibly the directory doesn't exist")
702
+ raise
703
+ end
704
+ if options[:lock_wait] > 0
705
+ begin
706
+ status = Timeout::timeout(options[:lock_wait]) do
707
+ return lock if lock.flock(File::LOCK_EX)
708
+ $logger.error("flock of #{options[:lock_file]} failed")
709
+ raise "flock failed"
710
+ end
711
+ rescue Timeout::Error => error
712
+ $logger.error("timed out waiting to lock")
713
+ raise
714
+ end
715
+ else
716
+ # zero is wait forever!
717
+ return lock if lock.flock(File::LOCK_EX)
718
+ $logger.error("flock of #{options[:lock_file]} failed")
719
+ raise "flock failed"
720
+ end
721
+ $logger.error("unable to obtain lock")
722
+ raise "unknown failure in locking file"
723
+ end
724
+ def self.unlock(lock)
725
+ unless lock.nil?
726
+ lock.flock(File::LOCK_UN)
727
+ lock.close()
728
+ end
729
+ end
685
730
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zfs_mgmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aran Cox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-24 00:00:00.000000000 Z
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubygems_version: 3.3.7
158
+ rubygems_version: 3.4.20
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Misc. helpers regarding snapshots and send/recv.