zfstools 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt CHANGED
@@ -1,20 +1,21 @@
1
- Copyright (c) 2012 Bryan Drewery
1
+ Copyright (c) 2012-2013, Bryan Drewery <bryan@shatow.net>
2
+ All rights reserved.
2
3
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
10
11
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY
13
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
16
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -31,11 +31,11 @@ This will handle automatically snapshotting datasets similar to time-sliderd fro
31
31
 
32
32
  #### Crontab
33
33
 
34
- 15,30,45 * * * * /usr/local/bin/zfs-auto-snapshot frequent 4
35
- 0 * * * * /usr/local/bin/zfs-auto-snapshot hourly 24
36
- 7 0 * * * /usr/local/bin/zfs-auto-snapshot daily 7
37
- 14 0 * * 7 /usr/local/bin/zfs-auto-snapshot weekly 4
38
- 28 0 1 * * /usr/local/bin/zfs-auto-snapshot monthly 12
34
+ 15,30,45 * * * * root /usr/local/bin/zfs-auto-snapshot frequent 4
35
+ 0 * * * * root /usr/local/bin/zfs-auto-snapshot hourly 24
36
+ 7 0 * * * root /usr/local/bin/zfs-auto-snapshot daily 7
37
+ 14 0 * * 7 root /usr/local/bin/zfs-auto-snapshot weekly 4
38
+ 28 0 1 * * root /usr/local/bin/zfs-auto-snapshot monthly 12
39
39
 
40
40
  #### Dataset setup
41
41
 
@@ -89,12 +89,7 @@ These settings should be set before importing any data.
89
89
  #### Script Usage
90
90
 
91
91
  Setup a `/root/.my.cnf` with the relevant information on where to connect to, with the proper username/password that has access to `FLUSH LOGS` and `FLUSH TABLES WITH READ LOCK`.
92
-
93
- #### Crontab
94
-
95
- */10 * * * * /usr/local/bin/zfs-snapshot-mysql DATASET
96
-
97
- * DATASET - The dataset that contains your mysql data
92
+ The `zfs-auto-snapshot` script will automatically flush the tables before saving the snapshots.
98
93
 
99
94
  ### zfs-cleanup-snapshots
100
95
 
data/README.rdoc CHANGED
@@ -14,5 +14,5 @@ Various scripts for administrating ZFS. Modeled after OpenSolaris time-slider
14
14
 
15
15
  == Copyright
16
16
 
17
- Copyright (c) 2012 Bryan Drewery. See LICENSE.txt for
17
+ Copyright (c) 2012-2013 Bryan Drewery. See LICENSE.txt for
18
18
  further details.
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ Jeweler::Tasks.new do |gem|
16
16
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
17
  gem.name = "zfstools"
18
18
  gem.homepage = "http://github.com/bdrewery/zfstools"
19
- gem.license = "MIT"
19
+ gem.license = "BSD"
20
20
  gem.summary = %Q{ZFSTools}
21
21
  gem.description = %Q{ZFS admin scripts, such as automatic snapshots, mysql snapshotting, scrubbing, etc.}
22
22
  gem.email = "bryan@shatow.net"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -10,6 +10,7 @@ opts = GetoptLong.new(
10
10
  [ "--utc", "-u", GetoptLong::NO_ARGUMENT ],
11
11
  [ "--keep-zero-sized-snapshots", "-k", GetoptLong::NO_ARGUMENT ],
12
12
  [ "--parallel-snapshots", "-p", GetoptLong::NO_ARGUMENT ],
13
+ [ "--pool", "-P", GetoptLong::REQUIRED_ARGUMENT ],
13
14
  [ "--dry-run", "-n", GetoptLong::NO_ARGUMENT ],
14
15
  [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ],
15
16
  [ "--debug", "-d", GetoptLong::NO_ARGUMENT ]
@@ -18,6 +19,7 @@ opts = GetoptLong.new(
18
19
  $use_utc = false
19
20
  $dry_run = false
20
21
  should_destroy_zero_sized_snapshots = true
22
+ pool = nil
21
23
  opts.each do |opt, arg|
22
24
  case opt
23
25
  when '--utc'
@@ -26,6 +28,8 @@ opts.each do |opt, arg|
26
28
  should_destroy_zero_sized_snapshots = false
27
29
  when '--parallel-snapshots'
28
30
  $use_threads = true
31
+ when '--pool'
32
+ pool = arg
29
33
  when '--dry-run'
30
34
  $dry_run = true
31
35
  when '--verbose'
@@ -38,13 +42,14 @@ end
38
42
 
39
43
  def usage
40
44
  puts <<-EOF
41
- Usage: $0 [-dknpuv] <INTERVAL> <KEEP>
45
+ Usage: #{$0} [-dknpuv] <INTERVAL> <KEEP>
42
46
  EOF
43
47
  format = " %-15s %s"
44
48
  puts format % ["-d", "Show debug output."]
45
49
  puts format % ["-k", "Keep zero-sized snapshots."]
46
50
  puts format % ["-n", "Do a dry-run. Nothing is committed. Only show what would be done."]
47
51
  puts format % ["-p", "Create snapshots in parallel."]
52
+ puts format % ["-P pool", "Act only on the specified pool."]
48
53
  puts format % ["-u", "Use UTC for snapshots."]
49
54
  puts format % ["-v", "Show what is being done."]
50
55
  puts format % ["INTERVAL", "The interval to snapshot."]
@@ -57,10 +62,10 @@ usage if ARGV.length < 2
57
62
  interval=ARGV[0]
58
63
  keep=ARGV[1].to_i
59
64
 
60
- datasets = find_eligible_datasets(interval)
65
+ datasets = find_eligible_datasets(interval, pool)
61
66
 
62
67
  # Generate new snapshots
63
68
  do_new_snapshots(datasets, interval) if keep > 0
64
69
 
65
70
  # Delete expired
66
- cleanup_expired_snapshots(datasets, interval, keep, should_destroy_zero_sized_snapshots)
71
+ cleanup_expired_snapshots(pool, datasets, interval, keep, should_destroy_zero_sized_snapshots)
@@ -7,20 +7,24 @@ require 'getoptlong'
7
7
  require 'zfstools'
8
8
 
9
9
  opts = GetoptLong.new(
10
- [ "--parallel-snapshots", "-p", GetoptLong::NO_ARGUMENT ],
11
10
  [ "--dry-run", "-n", GetoptLong::NO_ARGUMENT ],
11
+ [ "--parallel-snapshots", "-p", GetoptLong::NO_ARGUMENT ],
12
+ [ "--pool", "-P", GetoptLong::REQUIRED_ARGUMENT ],
12
13
  [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ],
13
14
  [ "--debug", "-d", GetoptLong::NO_ARGUMENT ]
14
15
  )
15
16
 
16
17
  $dry_run = false
17
18
  $use_threads = false
19
+ pool = nil
18
20
  opts.each do |opt, arg|
19
21
  case opt
20
22
  when '--dry-run'
21
23
  $dry_run = true
22
24
  when '--parallel-snapshots'
23
25
  $use_threads = true
26
+ when '--pool'
27
+ pool = arg
24
28
  when '--verbose'
25
29
  $verbose = true
26
30
  when '--debug'
@@ -31,19 +35,21 @@ end
31
35
 
32
36
  def usage
33
37
  puts <<-EOF
34
- Usage: $0 [-dnv]
38
+ Usage: #{$0} [-dnv]
35
39
  EOF
36
40
  format = " %-15s %s"
37
41
  puts format % ["-d", "Show debug output."]
38
42
  puts format % ["-n", "Do a dry-run. Nothing is committed. Only show what would be done."]
43
+ puts format % ["-p", "Create snapshots in parallel."]
44
+ puts format % ["-P pool", "Act only on the specified pool."]
39
45
  puts format % ["-v", "Show what is being done."]
40
46
  exit
41
47
  end
42
48
 
43
49
  usage if ARGV.length > 0
44
50
 
45
- snapshots = Zfs::Snapshot.list.select { |snapshot| snapshot.used == 0 and !snapshot.name.include?(snapshot_prefix) }
51
+ snapshots = Zfs::Snapshot.list(pool).select { |snapshot| snapshot.used == 0 and !snapshot.name.include?(snapshot_prefix) }
46
52
  ## Group into datasets
47
- datasets = Zfs::Dataset.list
53
+ datasets = Zfs::Dataset.list(pool)
48
54
  dataset_snapshots = group_snapshots_into_datasets(snapshots, datasets)
49
55
  dataset_snapshots = datasets_destroy_zero_sized_snapshots(dataset_snapshots)
@@ -27,7 +27,7 @@ end
27
27
 
28
28
  def usage
29
29
  puts <<-EOF
30
- Usage: $0 [-dnv] DATASET
30
+ Usage: #{$0} [-dnv] DATASET
31
31
  EOF
32
32
  format = " %-15s %s"
33
33
  puts format % ["-d", "Show debug output."]
@@ -20,10 +20,11 @@ module Zfs
20
20
  self
21
21
  end
22
22
 
23
- def self.list(properties=[])
23
+ def self.list(pool=nil, properties=[])
24
24
  datasets = []
25
25
  cmd_properties = ["name"] + properties
26
26
  cmd="zfs list -H -t filesystem,volume -o #{cmd_properties.join(",")} -s name"
27
+ cmd += " -r #{pool}" if pool
27
28
  puts cmd if $debug
28
29
  IO.popen cmd do |io|
29
30
  io.readlines.each do |line|
File without changes
data/lib/zfstools.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
- require 'zfs/snapshot'
4
- require 'zfs/dataset'
3
+ require 'zfstools/snapshot'
4
+ require 'zfstools/dataset'
5
5
 
6
6
  # Ruby 1.8 compat for select!
7
7
  class Hash
@@ -119,12 +119,12 @@ def filter_datasets(datasets, included_excluded_datasets, property)
119
119
  end
120
120
  end
121
121
 
122
- def find_eligible_datasets(interval)
122
+ def find_eligible_datasets(interval, pool)
123
123
  properties = [
124
124
  "#{snapshot_property}:#{interval}",
125
125
  snapshot_property,
126
126
  ]
127
- datasets = Zfs::Dataset.list(properties)
127
+ datasets = Zfs::Dataset.list(pool, properties)
128
128
 
129
129
  ### Group datasets into included/excluded for snapshotting
130
130
  included_excluded_datasets = {
@@ -209,9 +209,9 @@ def datasets_destroy_zero_sized_snapshots(dataset_snapshots)
209
209
  end
210
210
 
211
211
  ### Find and destroy expired snapshots
212
- def cleanup_expired_snapshots(datasets, interval, keep, should_destroy_zero_sized_snapshots)
212
+ def cleanup_expired_snapshots(pool, datasets, interval, keep, should_destroy_zero_sized_snapshots)
213
213
  ### Find all snapshots matching this interval
214
- snapshots = Zfs::Snapshot.list.select { |snapshot| snapshot.name.include?(snapshot_prefix(interval)) }
214
+ snapshots = Zfs::Snapshot.list(pool).select { |snapshot| snapshot.name.include?(snapshot_prefix(interval)) }
215
215
  dataset_snapshots = group_snapshots_into_datasets(snapshots, datasets['included'] + datasets['excluded'])
216
216
  ### Filter out datasets not included
217
217
  dataset_snapshots.select! { |dataset, snapshots| datasets['included'].include?(dataset) }
data/zfstools.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "zfstools"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bryan Drewery"]
12
- s.date = "2012-05-05"
12
+ s.date = "2013-02-04"
13
13
  s.description = "ZFS admin scripts, such as automatic snapshots, mysql snapshotting, scrubbing, etc."
14
14
  s.email = "bryan@shatow.net"
15
15
  s.executables = ["zfs-auto-snapshot", "zfs-cleanup-snapshots", "zfs-snapshot-mysql"]
@@ -34,15 +34,15 @@ Gem::Specification.new do |s|
34
34
  "features/step_definitions/zfstools_steps.rb",
35
35
  "features/support/env.rb",
36
36
  "features/zfstools.feature",
37
- "lib/zfs/dataset.rb",
38
- "lib/zfs/snapshot.rb",
39
37
  "lib/zfstools.rb",
38
+ "lib/zfstools/dataset.rb",
39
+ "lib/zfstools/snapshot.rb",
40
40
  "spec/spec_helper.rb",
41
41
  "spec/zfstools_spec.rb",
42
42
  "zfstools.gemspec"
43
43
  ]
44
44
  s.homepage = "http://github.com/bdrewery/zfstools"
45
- s.licenses = ["MIT"]
45
+ s.licenses = ["BSD"]
46
46
  s.require_paths = ["lib"]
47
47
  s.rubygems_version = "1.8.16"
48
48
  s.summary = "ZFSTools"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zfstools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-05 00:00:00.000000000Z
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &11694420 !ruby/object:Gem::Requirement
16
+ requirement: &20923260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11694420
24
+ version_requirements: *20923260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &11693740 !ruby/object:Gem::Requirement
27
+ requirement: &19966840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *11693740
35
+ version_requirements: *19966840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &11693000 !ruby/object:Gem::Requirement
38
+ requirement: &19964120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *11693000
46
+ version_requirements: *19964120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber
49
- requirement: &11692360 !ruby/object:Gem::Requirement
49
+ requirement: &19963020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *11692360
57
+ version_requirements: *19963020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &11691580 !ruby/object:Gem::Requirement
60
+ requirement: &19960960 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *11691580
68
+ version_requirements: *19960960
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &11690960 !ruby/object:Gem::Requirement
71
+ requirement: &19960160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.8.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *11690960
79
+ version_requirements: *19960160
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &11690240 !ruby/object:Gem::Requirement
82
+ requirement: &19975720 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *11690240
90
+ version_requirements: *19975720
91
91
  description: ZFS admin scripts, such as automatic snapshots, mysql snapshotting, scrubbing,
92
92
  etc.
93
93
  email: bryan@shatow.net
@@ -116,15 +116,15 @@ files:
116
116
  - features/step_definitions/zfstools_steps.rb
117
117
  - features/support/env.rb
118
118
  - features/zfstools.feature
119
- - lib/zfs/dataset.rb
120
- - lib/zfs/snapshot.rb
121
119
  - lib/zfstools.rb
120
+ - lib/zfstools/dataset.rb
121
+ - lib/zfstools/snapshot.rb
122
122
  - spec/spec_helper.rb
123
123
  - spec/zfstools_spec.rb
124
124
  - zfstools.gemspec
125
125
  homepage: http://github.com/bdrewery/zfstools
126
126
  licenses:
127
- - MIT
127
+ - BSD
128
128
  post_install_message:
129
129
  rdoc_options: []
130
130
  require_paths:
@@ -137,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  segments:
139
139
  - 0
140
- hash: -3654737398168327610
140
+ hash: 1946936266483183679
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  none: false
143
143
  requirements: