zfstools 0.3.2 → 0.3.7
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 +7 -0
- data/README.md +1 -1
- data/bin/zfs-auto-snapshot +44 -35
- data/bin/zfs-cleanup-snapshots +32 -27
- data/bin/zfs-snapshot-mysql +24 -19
- data/lib/zfstools/dataset.rb +3 -2
- data/lib/zfstools/features.rb +35 -0
- data/lib/zfstools/pool.rb +48 -0
- data/lib/zfstools/snapshot.rb +75 -7
- data/lib/zfstools.rb +16 -28
- metadata +49 -132
- data/.document +0 -5
- data/.rspec +0 -1
- data/Gemfile +0 -16
- data/Gemfile.lock +0 -50
- data/README.rdoc +0 -18
- data/Rakefile +0 -53
- data/VERSION +0 -1
- data/features/step_definitions/zfstools_steps.rb +0 -0
- data/features/support/env.rb +0 -13
- data/features/zfstools.feature +0 -9
- data/spec/spec_helper.rb +0 -32
- data/spec/zfstools_spec.rb +0 -251
- data/zfstools.gemspec +0 -80
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9ed5acee06cf644784291190e8b1d2043fc94b4bb97c534c7c6d0bb606db762b
|
|
4
|
+
data.tar.gz: dacad69de06bbcfc703009daf5e89a0a661884ea6cd6ceb3a0c9d9963c87c106
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e43ec241944a7b28d89ed75628785e62c37b2301a9bf2efb3467e2c07f0c7e40b7812e7172454ca7606e3ec3ce33cdee3fea5a890a894a526f289c8a94a1f6bf
|
|
7
|
+
data.tar.gz: f9fbd7b2123c723e905c046f8a435331cbeb3fa450554fb2a48b38ce3e03cfdd1a255c2584d893c01533ea73ffb91196bf4b392c1d18cf963ff3d0201cfd2d01
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ZFS Tools
|
|
2
2
|
|
|
3
|
-
Various scripts for administrating ZFS. Modeled after [time-sliderd](http://mail.opensolaris.org/pipermail/zfs-discuss/2009-November/033882.html) and [ZFS Automatic Snapshots](https://blogs.
|
|
3
|
+
Various scripts for administrating ZFS. Modeled after [time-sliderd](https://web.archive.org/web/20091219060106/http://mail.opensolaris.org/pipermail/zfs-discuss/2009-November/033882.html) and [ZFS Automatic Snapshots](https://web.archive.org/web/20090707205453/http://blogs.sun.com/timf/entry/zfs_automatic_snapshots_0_12) from OpenSolaris
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
6
|
|
data/bin/zfs-auto-snapshot
CHANGED
|
@@ -13,48 +13,57 @@ opts = GetoptLong.new(
|
|
|
13
13
|
[ "--pool", "-P", GetoptLong::REQUIRED_ARGUMENT ],
|
|
14
14
|
[ "--dry-run", "-n", GetoptLong::NO_ARGUMENT ],
|
|
15
15
|
[ "--verbose", "-v", GetoptLong::NO_ARGUMENT ],
|
|
16
|
-
[ "--debug", "-d", GetoptLong::NO_ARGUMENT ]
|
|
16
|
+
[ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
|
|
17
|
+
[ "--snapshot-prefix", "-s", GetoptLong::REQUIRED_ARGUMENT ]
|
|
17
18
|
)
|
|
18
19
|
|
|
20
|
+
# Print the usage, on stderr for a non-zero status, and exit with status.
|
|
21
|
+
def usage(status = 0)
|
|
22
|
+
out = status.zero? ? $stdout : $stderr
|
|
23
|
+
out.puts <<-EOF
|
|
24
|
+
Usage: #{$0} [-dknpuv] <INTERVAL> <KEEP>
|
|
25
|
+
EOF
|
|
26
|
+
format = " %-15s %s"
|
|
27
|
+
out.puts format % ["-d", "Show debug output."]
|
|
28
|
+
out.puts format % ["-k", "Keep zero-sized snapshots."]
|
|
29
|
+
out.puts format % ["-n", "Do a dry-run. Nothing is committed. Only show what would be done."]
|
|
30
|
+
out.puts format % ["-p", "Create snapshots in parallel."]
|
|
31
|
+
out.puts format % ["-P pool", "Act only on the specified pool."]
|
|
32
|
+
out.puts format % ["-u", "Use UTC for snapshots."]
|
|
33
|
+
out.puts format % ["-s", "Specfic snapshot prefix"]
|
|
34
|
+
out.puts format % ["-v", "Show what is being done."]
|
|
35
|
+
out.puts format % ["INTERVAL", "The interval to snapshot."]
|
|
36
|
+
out.puts format % ["KEEP", "How many snapshots to keep."]
|
|
37
|
+
exit status
|
|
38
|
+
end
|
|
39
|
+
|
|
19
40
|
$use_utc = false
|
|
20
41
|
$dry_run = false
|
|
21
42
|
should_destroy_zero_sized_snapshots = true
|
|
22
43
|
pool = nil
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
pool
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
begin
|
|
45
|
+
opts.each do |opt, arg|
|
|
46
|
+
case opt
|
|
47
|
+
when '--utc'
|
|
48
|
+
$use_utc = true
|
|
49
|
+
when '--keep-zero-sized-snapshots'
|
|
50
|
+
should_destroy_zero_sized_snapshots = false
|
|
51
|
+
when '--parallel-snapshots'
|
|
52
|
+
$use_threads = true
|
|
53
|
+
when '--pool'
|
|
54
|
+
pool = arg
|
|
55
|
+
when '--dry-run'
|
|
56
|
+
$dry_run = true
|
|
57
|
+
when '--verbose'
|
|
58
|
+
$verbose = true
|
|
59
|
+
when '--debug'
|
|
60
|
+
$debug = true
|
|
61
|
+
when '--snapshot-prefix'
|
|
62
|
+
$snapshot_prefix = arg
|
|
63
|
+
end
|
|
39
64
|
end
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def usage
|
|
44
|
-
puts <<-EOF
|
|
45
|
-
Usage: #{$0} [-dknpuv] <INTERVAL> <KEEP>
|
|
46
|
-
EOF
|
|
47
|
-
format = " %-15s %s"
|
|
48
|
-
puts format % ["-d", "Show debug output."]
|
|
49
|
-
puts format % ["-k", "Keep zero-sized snapshots."]
|
|
50
|
-
puts format % ["-n", "Do a dry-run. Nothing is committed. Only show what would be done."]
|
|
51
|
-
puts format % ["-p", "Create snapshots in parallel."]
|
|
52
|
-
puts format % ["-P pool", "Act only on the specified pool."]
|
|
53
|
-
puts format % ["-u", "Use UTC for snapshots."]
|
|
54
|
-
puts format % ["-v", "Show what is being done."]
|
|
55
|
-
puts format % ["INTERVAL", "The interval to snapshot."]
|
|
56
|
-
puts format % ["KEEP", "How many snapshots to keep."]
|
|
57
|
-
exit
|
|
65
|
+
rescue GetoptLong::Error
|
|
66
|
+
usage(1)
|
|
58
67
|
end
|
|
59
68
|
|
|
60
69
|
usage if ARGV.length < 2
|
data/bin/zfs-cleanup-snapshots
CHANGED
|
@@ -14,41 +14,46 @@ opts = GetoptLong.new(
|
|
|
14
14
|
[ "--debug", "-d", GetoptLong::NO_ARGUMENT ]
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
+
# Print the usage, on stderr for a non-zero status, and exit with status.
|
|
18
|
+
def usage(status = 0)
|
|
19
|
+
out = status.zero? ? $stdout : $stderr
|
|
20
|
+
out.puts <<-EOF
|
|
21
|
+
Usage: #{$0} [-dnv]
|
|
22
|
+
EOF
|
|
23
|
+
format = " %-15s %s"
|
|
24
|
+
out.puts format % ["-d", "Show debug output."]
|
|
25
|
+
out.puts format % ["-n", "Do a dry-run. Nothing is committed. Only show what would be done."]
|
|
26
|
+
out.puts format % ["-p", "Create snapshots in parallel."]
|
|
27
|
+
out.puts format % ["-P pool", "Act only on the specified pool."]
|
|
28
|
+
out.puts format % ["-v", "Show what is being done."]
|
|
29
|
+
exit status
|
|
30
|
+
end
|
|
31
|
+
|
|
17
32
|
$dry_run = false
|
|
18
33
|
$use_threads = false
|
|
19
34
|
pool = nil
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
pool
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
begin
|
|
36
|
+
opts.each do |opt, arg|
|
|
37
|
+
case opt
|
|
38
|
+
when '--dry-run'
|
|
39
|
+
$dry_run = true
|
|
40
|
+
when '--parallel-snapshots'
|
|
41
|
+
$use_threads = true
|
|
42
|
+
when '--pool'
|
|
43
|
+
pool = arg
|
|
44
|
+
when '--verbose'
|
|
45
|
+
$verbose = true
|
|
46
|
+
when '--debug'
|
|
47
|
+
$debug = true
|
|
48
|
+
end
|
|
32
49
|
end
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def usage
|
|
37
|
-
puts <<-EOF
|
|
38
|
-
Usage: #{$0} [-dnv]
|
|
39
|
-
EOF
|
|
40
|
-
format = " %-15s %s"
|
|
41
|
-
puts format % ["-d", "Show debug output."]
|
|
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."]
|
|
45
|
-
puts format % ["-v", "Show what is being done."]
|
|
46
|
-
exit
|
|
50
|
+
rescue GetoptLong::Error
|
|
51
|
+
usage(1)
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
usage if ARGV.length > 0
|
|
50
55
|
|
|
51
|
-
snapshots = Zfs::Snapshot.list(pool).select { |snapshot| snapshot.used == 0 and !snapshot.name.include?(snapshot_prefix) }
|
|
56
|
+
snapshots = Zfs::Snapshot.list(pool, {'recursive' => true}).select { |snapshot| snapshot.used == 0 and !snapshot.name.include?(snapshot_prefix) }
|
|
52
57
|
## Group into datasets
|
|
53
58
|
datasets = Zfs::Dataset.list(pool)
|
|
54
59
|
dataset_snapshots = group_snapshots_into_datasets(snapshots, datasets)
|
data/bin/zfs-snapshot-mysql
CHANGED
|
@@ -12,28 +12,33 @@ opts = GetoptLong.new(
|
|
|
12
12
|
[ "--debug", "-d", GetoptLong::NO_ARGUMENT ]
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
$dry_run = true
|
|
20
|
-
when '--verbose'
|
|
21
|
-
$verbose = true
|
|
22
|
-
when '--debug'
|
|
23
|
-
$debug = true
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def usage
|
|
29
|
-
puts <<-EOF
|
|
15
|
+
# Print the usage, on stderr for a non-zero status, and exit with status.
|
|
16
|
+
def usage(status = 0)
|
|
17
|
+
out = status.zero? ? $stdout : $stderr
|
|
18
|
+
out.puts <<-EOF
|
|
30
19
|
Usage: #{$0} [-dnv] DATASET
|
|
31
20
|
EOF
|
|
32
21
|
format = " %-15s %s"
|
|
33
|
-
puts format % ["-d", "Show debug output."]
|
|
34
|
-
puts format % ["-n", "Do a dry-run. Nothing is committed. Only show what would be done."]
|
|
35
|
-
puts format % ["-v", "Show what is being done."]
|
|
36
|
-
exit
|
|
22
|
+
out.puts format % ["-d", "Show debug output."]
|
|
23
|
+
out.puts format % ["-n", "Do a dry-run. Nothing is committed. Only show what would be done."]
|
|
24
|
+
out.puts format % ["-v", "Show what is being done."]
|
|
25
|
+
exit status
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
$dry_run = false
|
|
29
|
+
begin
|
|
30
|
+
opts.each do |opt, arg|
|
|
31
|
+
case opt
|
|
32
|
+
when '--dry-run'
|
|
33
|
+
$dry_run = true
|
|
34
|
+
when '--verbose'
|
|
35
|
+
$verbose = true
|
|
36
|
+
when '--debug'
|
|
37
|
+
$debug = true
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
rescue GetoptLong::Error
|
|
41
|
+
usage(1)
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
usage if ARGV.length < 1
|
data/lib/zfstools/dataset.rb
CHANGED
|
@@ -22,15 +22,16 @@ module Zfs
|
|
|
22
22
|
|
|
23
23
|
def self.list(pool=nil, properties=[])
|
|
24
24
|
datasets = []
|
|
25
|
-
cmd_properties = ["name"] + properties
|
|
25
|
+
cmd_properties = ["name", "type"] + properties
|
|
26
26
|
cmd="zfs list -H -t filesystem,volume -o #{cmd_properties.join(",")} -s name"
|
|
27
27
|
cmd += " -r #{pool}" if pool
|
|
28
28
|
puts cmd if $debug
|
|
29
29
|
IO.popen cmd do |io|
|
|
30
30
|
io.readlines.each do |line|
|
|
31
|
-
values = line.split
|
|
31
|
+
values = line.chomp.split("\t")
|
|
32
32
|
name = values.shift
|
|
33
33
|
dataset_properties = {}
|
|
34
|
+
dataset_properties['type'] = values.shift
|
|
34
35
|
properties.each_with_index do |property_name, i|
|
|
35
36
|
value = values[i]
|
|
36
37
|
next if value == '-'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Zfs
|
|
2
|
+
class Features
|
|
3
|
+
@@have_bookmarks = nil
|
|
4
|
+
@@have_multi_snap = nil
|
|
5
|
+
@@have_written = nil
|
|
6
|
+
|
|
7
|
+
# https://www.illumos.org/issues/4369
|
|
8
|
+
def self.has_bookmarks
|
|
9
|
+
if @@have_bookmarks.nil?
|
|
10
|
+
pools = Zfs::Pool.list(nil, ["feature@bookmarks"])
|
|
11
|
+
has_bookmarks = pools.find { |pool| pool.properties.include?('feature@bookmarks') }
|
|
12
|
+
@@have_bookmarks = !has_bookmarks.nil?
|
|
13
|
+
end
|
|
14
|
+
@@have_bookmarks
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# https://www.illumos.org/issues/2900
|
|
18
|
+
def self.has_multi_snap
|
|
19
|
+
if @@have_multi_snap.nil?
|
|
20
|
+
# Check for bookmark support, which we'll piggyback on for 'zfs snapshot snap1 snap2 snapN'
|
|
21
|
+
@@have_multi_snap = self.has_bookmarks
|
|
22
|
+
end
|
|
23
|
+
@@have_multi_snap
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# https://www.illumos.org/issues/1645
|
|
27
|
+
def self.has_written
|
|
28
|
+
if @@have_written.nil?
|
|
29
|
+
# Check for bookmark support, which we'll piggyback on for 'written' support
|
|
30
|
+
@@have_written = self.has_bookmarks
|
|
31
|
+
end
|
|
32
|
+
@@have_written
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Zfs
|
|
2
|
+
class Pool
|
|
3
|
+
attr_reader :name
|
|
4
|
+
attr_reader :properties
|
|
5
|
+
|
|
6
|
+
def initialize(name, properties={})
|
|
7
|
+
@name = name
|
|
8
|
+
@properties = properties
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def ==(pool)
|
|
12
|
+
pool.equal?(self) || (pool && pool.name == @name)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_s()
|
|
16
|
+
res = ""
|
|
17
|
+
@properties.each do |property, value|
|
|
18
|
+
res += "[#{@name}] #{property}: #{value}\n"
|
|
19
|
+
end
|
|
20
|
+
res
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.list(name=nil, cmd_properties=[])
|
|
24
|
+
pools = []
|
|
25
|
+
cmd_properties << "all" if cmd_properties.empty?
|
|
26
|
+
# -H,-p and -o are Illumos improvements. Failure means it won't support
|
|
27
|
+
# new features.
|
|
28
|
+
cmd="zpool get -H -p -o name,property,value #{cmd_properties.join(",")}"
|
|
29
|
+
cmd += " #{name}" if name
|
|
30
|
+
cmd += " 2>/dev/null"
|
|
31
|
+
puts cmd if $debug
|
|
32
|
+
pool_properties = Hash.new{|pool, properties| pool[properties] = {}}
|
|
33
|
+
IO.popen cmd do |io|
|
|
34
|
+
io.readlines.each do |line|
|
|
35
|
+
values = line.chomp.split("\t")
|
|
36
|
+
name = values.shift
|
|
37
|
+
property = values.shift
|
|
38
|
+
value = values.shift
|
|
39
|
+
pool_properties[name][property] = value
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
pool_properties.each do |name, properties|
|
|
43
|
+
pools << self.new(name, properties)
|
|
44
|
+
end
|
|
45
|
+
pools
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/lib/zfstools/snapshot.rb
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
require 'enumerator'
|
|
2
|
+
require 'shellwords'
|
|
3
|
+
require 'zfstools/features'
|
|
4
|
+
|
|
1
5
|
module Zfs
|
|
2
6
|
class Snapshot
|
|
3
7
|
@@stale_snapshot_size = false
|
|
@@ -9,7 +13,7 @@ module Zfs
|
|
|
9
13
|
|
|
10
14
|
def used
|
|
11
15
|
if @used.nil? or @@stale_snapshot_size
|
|
12
|
-
cmd = "zfs get -Hp -o value used
|
|
16
|
+
cmd = "zfs get -Hp -o value used " + @name.shellescape
|
|
13
17
|
puts cmd if $debug
|
|
14
18
|
@used = %x[#{cmd}].to_i
|
|
15
19
|
end
|
|
@@ -20,7 +24,7 @@ module Zfs
|
|
|
20
24
|
if @used != 0
|
|
21
25
|
return false
|
|
22
26
|
end
|
|
23
|
-
used
|
|
27
|
+
used == 0
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
### List all snapshots
|
|
@@ -30,12 +34,11 @@ module Zfs
|
|
|
30
34
|
flags << "-d 1" if dataset and !options['recursive']
|
|
31
35
|
flags << "-r" if options['recursive']
|
|
32
36
|
cmd = "zfs list #{flags.join(" ")} -H -t snapshot -o name,used -S name"
|
|
33
|
-
cmd += "
|
|
37
|
+
cmd += " " + dataset.shellescape if dataset
|
|
34
38
|
puts cmd if $debug
|
|
35
39
|
IO.popen cmd do |io|
|
|
36
40
|
io.readlines.each do |line|
|
|
37
|
-
line.chomp
|
|
38
|
-
snapshot_name,used = line.split(' ')
|
|
41
|
+
snapshot_name,used = line.chomp.split("\t")
|
|
39
42
|
snapshots << self.new(snapshot_name, used.to_i)
|
|
40
43
|
end
|
|
41
44
|
end
|
|
@@ -46,7 +49,12 @@ module Zfs
|
|
|
46
49
|
def self.create(snapshot, options = {})
|
|
47
50
|
flags=[]
|
|
48
51
|
flags << "-r" if options['recursive']
|
|
49
|
-
cmd = "zfs snapshot #{flags.join(" ")}
|
|
52
|
+
cmd = "zfs snapshot #{flags.join(" ")} "
|
|
53
|
+
if snapshot.kind_of?(Array)
|
|
54
|
+
cmd += snapshot.shelljoin
|
|
55
|
+
else
|
|
56
|
+
cmd += snapshot.shellescape
|
|
57
|
+
end
|
|
50
58
|
|
|
51
59
|
if options['db']
|
|
52
60
|
case options['db']
|
|
@@ -71,6 +79,66 @@ module Zfs
|
|
|
71
79
|
system(cmd) unless $dry_run
|
|
72
80
|
end
|
|
73
81
|
|
|
82
|
+
def self.create_many(snapshot_name, datasets, options={})
|
|
83
|
+
if not options['single']
|
|
84
|
+
# If any of the datasets contain a db it needs to be split out
|
|
85
|
+
db_datasets = []
|
|
86
|
+
datasets.reject! do |dataset|
|
|
87
|
+
if dataset.db
|
|
88
|
+
db_datasets << dataset
|
|
89
|
+
true
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
# Create db snapshots individually
|
|
93
|
+
self.create_many(snapshot_name, db_datasets, options.merge({'single' => true}))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
return if datasets.empty?
|
|
97
|
+
|
|
98
|
+
if not options['single'] and Zfs::Features.has_multi_snap
|
|
99
|
+
snapshots = []
|
|
100
|
+
max_length = 0
|
|
101
|
+
datasets.each do |dataset|
|
|
102
|
+
snapshot = "#{dataset.name}@#{snapshot_name}"
|
|
103
|
+
max_length = [snapshot.length, max_length].max
|
|
104
|
+
snapshots << snapshot
|
|
105
|
+
end
|
|
106
|
+
# XXX: The ARG_MAX checks are not ideal here but there is
|
|
107
|
+
# not yet a reason to generalize it to elsewhere.
|
|
108
|
+
# Etc::sysconf https://bugs.ruby-lang.org/issues/9842 would be nice.
|
|
109
|
+
if not defined?($arg_max)
|
|
110
|
+
begin
|
|
111
|
+
$arg_max = `getconf ARG_MAX`.chomp.to_i
|
|
112
|
+
rescue Errno::ENOENT
|
|
113
|
+
$arg_max = 4096
|
|
114
|
+
end
|
|
115
|
+
# Env and escaping slack
|
|
116
|
+
$arg_max = $arg_max - 1024
|
|
117
|
+
end
|
|
118
|
+
# Lazy chunking
|
|
119
|
+
chunks = $arg_max / max_length
|
|
120
|
+
# Group by pool
|
|
121
|
+
pooled_snapshots = snapshots.group_by { |snapshot| snapshot.split('@')[0].split('/')[0] }
|
|
122
|
+
pooled_snapshots.each do |pool, snapshots|
|
|
123
|
+
snapshots.each_slice(chunks) do |snapshots_chunk|
|
|
124
|
+
self.create(snapshots_chunk, options)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
else
|
|
128
|
+
# Have to brute force.
|
|
129
|
+
threads = []
|
|
130
|
+
datasets.each do |dataset|
|
|
131
|
+
threads << Thread.new do
|
|
132
|
+
self.create("#{dataset.name}@#{snapshot_name}",
|
|
133
|
+
'recursive' => options['recursive'] || false,
|
|
134
|
+
'db' => dataset.db)
|
|
135
|
+
end
|
|
136
|
+
threads.last.join unless $use_threads
|
|
137
|
+
end
|
|
138
|
+
threads.each { |th| th.join }
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
74
142
|
### Destroy a snapshot
|
|
75
143
|
def destroy(options = {})
|
|
76
144
|
# If destroying a snapshot, need to flag all other snapshot sizes as stale
|
|
@@ -79,7 +147,7 @@ module Zfs
|
|
|
79
147
|
# Default to deferred snapshot destroying
|
|
80
148
|
flags=["-d"]
|
|
81
149
|
flags << "-r" if options['recursive']
|
|
82
|
-
cmd = "zfs destroy #{flags.join(" ")}
|
|
150
|
+
cmd = "zfs destroy #{flags.join(" ")} " + @name.shellescape
|
|
83
151
|
puts cmd if $debug
|
|
84
152
|
system(cmd) unless $dry_run
|
|
85
153
|
end
|
data/lib/zfstools.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
|
2
2
|
|
|
3
|
-
require 'zfstools/
|
|
3
|
+
require 'zfstools/pool'
|
|
4
4
|
require 'zfstools/dataset'
|
|
5
|
+
require 'zfstools/snapshot'
|
|
5
6
|
|
|
6
7
|
# Ruby 1.8 compat for select!
|
|
7
8
|
class Hash
|
|
@@ -15,12 +16,12 @@ def snapshot_property
|
|
|
15
16
|
"com.sun:auto-snapshot"
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
def snapshot_prefix(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
def snapshot_prefix()
|
|
20
|
+
$snapshot_prefix ? $snapshot_prefix : "zfs-auto-snap"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def snapshot_prefix_interval(interval)
|
|
24
|
+
snapshot_prefix() + "_#{interval}-"
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def snapshot_format
|
|
@@ -34,7 +35,7 @@ def snapshot_name(interval)
|
|
|
34
35
|
else
|
|
35
36
|
date = Time.now.strftime(snapshot_format)
|
|
36
37
|
end
|
|
37
|
-
|
|
38
|
+
snapshot_prefix_interval(interval) + date
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
### Find which datasets can be recursively snapshotted
|
|
@@ -108,12 +109,13 @@ def filter_datasets(datasets, included_excluded_datasets, property)
|
|
|
108
109
|
all_datasets = included_excluded_datasets['included'] + included_excluded_datasets['excluded']
|
|
109
110
|
|
|
110
111
|
datasets.each do |dataset|
|
|
111
|
-
# Skip unmounted datasets
|
|
112
|
-
next if dataset.properties['mounted'] == 'no'
|
|
113
112
|
# If the dataset is already included/excluded, skip it (for override checking)
|
|
114
113
|
next if all_datasets.include? dataset
|
|
115
114
|
value = dataset.properties[property]
|
|
116
|
-
|
|
115
|
+
# Exclude unmounted datasets.
|
|
116
|
+
if (dataset.properties['mounted'] == "yes" or
|
|
117
|
+
dataset.properties['type'] == "volume") and
|
|
118
|
+
["true","mysql","postgresql"].include? value
|
|
117
119
|
included_excluded_datasets['included'] << dataset
|
|
118
120
|
elsif value
|
|
119
121
|
included_excluded_datasets['excluded'] << dataset
|
|
@@ -148,24 +150,10 @@ end
|
|
|
148
150
|
def do_new_snapshots(datasets, interval)
|
|
149
151
|
snapshot_name = snapshot_name(interval)
|
|
150
152
|
|
|
151
|
-
threads = []
|
|
152
153
|
# Snapshot single
|
|
153
|
-
datasets['single']
|
|
154
|
-
threads << Thread.new do
|
|
155
|
-
Zfs::Snapshot.create("#{dataset.name}@#{snapshot_name}", 'db' => dataset.db)
|
|
156
|
-
end
|
|
157
|
-
threads.last.join unless $use_threads
|
|
158
|
-
end
|
|
159
|
-
|
|
154
|
+
Zfs::Snapshot.create_many(snapshot_name, datasets['single'])
|
|
160
155
|
# Snapshot recursive
|
|
161
|
-
datasets['recursive']
|
|
162
|
-
threads << Thread.new do
|
|
163
|
-
Zfs::Snapshot.create("#{dataset.name}@#{snapshot_name}", 'recursive' => true, 'db' => dataset.db)
|
|
164
|
-
end
|
|
165
|
-
threads.last.join unless $use_threads
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
threads.each { |th| th.join }
|
|
156
|
+
Zfs::Snapshot.create_many(snapshot_name, datasets['recursive'], 'recursive'=>true)
|
|
169
157
|
end
|
|
170
158
|
|
|
171
159
|
def group_snapshots_into_datasets(snapshots, datasets)
|
|
@@ -214,7 +202,7 @@ end
|
|
|
214
202
|
### Find and destroy expired snapshots
|
|
215
203
|
def cleanup_expired_snapshots(pool, datasets, interval, keep, should_destroy_zero_sized_snapshots)
|
|
216
204
|
### Find all snapshots matching this interval
|
|
217
|
-
snapshots = Zfs::Snapshot.list(pool).select { |snapshot| snapshot.name.include?(
|
|
205
|
+
snapshots = Zfs::Snapshot.list(pool, {'recursive' => true}).select { |snapshot| snapshot.name.include?(snapshot_prefix_interval(interval)) }
|
|
218
206
|
dataset_snapshots = group_snapshots_into_datasets(snapshots, datasets['included'] + datasets['excluded'])
|
|
219
207
|
### Filter out datasets not included
|
|
220
208
|
dataset_snapshots.select! { |dataset, snapshots| datasets['included'].include?(dataset) }
|
metadata
CHANGED
|
@@ -1,153 +1,70 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zfstools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.3.7
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
|
-
- Bryan Drewery
|
|
9
|
-
autorequire:
|
|
7
|
+
- Bryan Drewery
|
|
10
8
|
bindir: bin
|
|
11
9
|
cert_chain: []
|
|
12
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
11
|
dependencies:
|
|
14
|
-
- !ruby/object:Gem::Dependency
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0.7'
|
|
33
|
-
type: :development
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: *21999840
|
|
36
|
-
- !ruby/object:Gem::Dependency
|
|
37
|
-
name: rdoc
|
|
38
|
-
requirement: &21999280 !ruby/object:Gem::Requirement
|
|
39
|
-
none: false
|
|
40
|
-
requirements:
|
|
41
|
-
- - ~>
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
version: '3.12'
|
|
44
|
-
type: :development
|
|
45
|
-
prerelease: false
|
|
46
|
-
version_requirements: *21999280
|
|
47
|
-
- !ruby/object:Gem::Dependency
|
|
48
|
-
name: cucumber
|
|
49
|
-
requirement: &21998580 !ruby/object:Gem::Requirement
|
|
50
|
-
none: false
|
|
51
|
-
requirements:
|
|
52
|
-
- - ! '>='
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
|
-
type: :development
|
|
56
|
-
prerelease: false
|
|
57
|
-
version_requirements: *21998580
|
|
58
|
-
- !ruby/object:Gem::Dependency
|
|
59
|
-
name: bundler
|
|
60
|
-
requirement: &21997600 !ruby/object:Gem::Requirement
|
|
61
|
-
none: false
|
|
62
|
-
requirements:
|
|
63
|
-
- - ~>
|
|
64
|
-
- !ruby/object:Gem::Version
|
|
65
|
-
version: 1.0.0
|
|
66
|
-
type: :development
|
|
67
|
-
prerelease: false
|
|
68
|
-
version_requirements: *21997600
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: jeweler
|
|
71
|
-
requirement: &22012480 !ruby/object:Gem::Requirement
|
|
72
|
-
none: false
|
|
73
|
-
requirements:
|
|
74
|
-
- - ~>
|
|
75
|
-
- !ruby/object:Gem::Version
|
|
76
|
-
version: 1.8.3
|
|
77
|
-
type: :development
|
|
78
|
-
prerelease: false
|
|
79
|
-
version_requirements: *22012480
|
|
80
|
-
- !ruby/object:Gem::Dependency
|
|
81
|
-
name: simplecov
|
|
82
|
-
requirement: &22008220 !ruby/object:Gem::Requirement
|
|
83
|
-
none: false
|
|
84
|
-
requirements:
|
|
85
|
-
- - ! '>='
|
|
86
|
-
- !ruby/object:Gem::Version
|
|
87
|
-
version: '0'
|
|
88
|
-
type: :development
|
|
89
|
-
prerelease: false
|
|
90
|
-
version_requirements: *22008220
|
|
91
|
-
description: ZFS admin scripts, such as automatic snapshots, mysql snapshotting, scrubbing,
|
|
92
|
-
etc.
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: getoptlong
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
-
|
|
17
|
+
- ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: "0"
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
-
|
|
25
|
+
- ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: "0"
|
|
28
|
+
description: "ZFS admin scripts, such as automatic snapshots, mysql snapshotting, scrubbing, etc."
|
|
93
29
|
email: bryan@shatow.net
|
|
94
30
|
executables:
|
|
95
|
-
- zfs-auto-snapshot
|
|
96
|
-
- zfs-cleanup-snapshots
|
|
97
|
-
- zfs-snapshot-mysql
|
|
31
|
+
- zfs-auto-snapshot
|
|
32
|
+
- zfs-cleanup-snapshots
|
|
33
|
+
- zfs-snapshot-mysql
|
|
98
34
|
extensions: []
|
|
99
|
-
extra_rdoc_files:
|
|
100
|
-
- LICENSE.txt
|
|
101
|
-
- README.md
|
|
102
|
-
- README.rdoc
|
|
35
|
+
extra_rdoc_files: []
|
|
103
36
|
files:
|
|
104
|
-
- .
|
|
105
|
-
- .
|
|
106
|
-
-
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
|
|
115
|
-
- bin/zfs-snapshot-mysql
|
|
116
|
-
- features/step_definitions/zfstools_steps.rb
|
|
117
|
-
- features/support/env.rb
|
|
118
|
-
- features/zfstools.feature
|
|
119
|
-
- lib/zfstools.rb
|
|
120
|
-
- lib/zfstools/dataset.rb
|
|
121
|
-
- lib/zfstools/snapshot.rb
|
|
122
|
-
- spec/spec_helper.rb
|
|
123
|
-
- spec/zfstools_spec.rb
|
|
124
|
-
- zfstools.gemspec
|
|
125
|
-
homepage: http://github.com/bdrewery/zfstools
|
|
37
|
+
- LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- bin/zfs-auto-snapshot
|
|
40
|
+
- bin/zfs-cleanup-snapshots
|
|
41
|
+
- bin/zfs-snapshot-mysql
|
|
42
|
+
- lib/zfstools.rb
|
|
43
|
+
- lib/zfstools/dataset.rb
|
|
44
|
+
- lib/zfstools/features.rb
|
|
45
|
+
- lib/zfstools/pool.rb
|
|
46
|
+
- lib/zfstools/snapshot.rb
|
|
47
|
+
homepage: "https://github.com/bdrewery/zfstools"
|
|
126
48
|
licenses:
|
|
127
|
-
- BSD
|
|
128
|
-
|
|
49
|
+
- BSD-2-Clause
|
|
50
|
+
metadata: {}
|
|
129
51
|
rdoc_options: []
|
|
130
52
|
require_paths:
|
|
131
|
-
- lib
|
|
53
|
+
- lib
|
|
132
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
|
-
none: false
|
|
134
55
|
requirements:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
- 0
|
|
140
|
-
hash: 1362403940350348159
|
|
56
|
+
-
|
|
57
|
+
- ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: "0"
|
|
141
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
|
-
none: false
|
|
143
61
|
requirements:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
62
|
+
-
|
|
63
|
+
- ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: "0"
|
|
147
66
|
requirements: []
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
specification_version: 3
|
|
152
|
-
summary: ZFSTools
|
|
67
|
+
rubygems_version: 4.1.0
|
|
68
|
+
specification_version: 4
|
|
69
|
+
summary: Various scripts for administrating ZFS.
|
|
153
70
|
test_files: []
|
data/.document
DELETED
data/.rspec
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--color
|
data/Gemfile
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
source "http://rubygems.org"
|
|
2
|
-
# Add dependencies required to use your gem here.
|
|
3
|
-
# Example:
|
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
|
5
|
-
|
|
6
|
-
# Add dependencies to develop your gem here.
|
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
|
8
|
-
group :development do
|
|
9
|
-
gem "rspec", "~> 2.8.0"
|
|
10
|
-
gem "yard", "~> 0.7"
|
|
11
|
-
gem "rdoc", "~> 3.12"
|
|
12
|
-
gem "cucumber", ">= 0"
|
|
13
|
-
gem "bundler", "~> 1.0.0"
|
|
14
|
-
gem "jeweler", "~> 1.8.3"
|
|
15
|
-
gem (RUBY_VERSION =~ /^1\.9/ ? "simplecov" : "rcov"), ">= 0"
|
|
16
|
-
end
|
data/Gemfile.lock
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
GEM
|
|
2
|
-
remote: http://rubygems.org/
|
|
3
|
-
specs:
|
|
4
|
-
builder (3.0.0)
|
|
5
|
-
cucumber (1.1.4)
|
|
6
|
-
builder (>= 2.1.2)
|
|
7
|
-
diff-lcs (>= 1.1.2)
|
|
8
|
-
gherkin (~> 2.7.1)
|
|
9
|
-
json (>= 1.4.6)
|
|
10
|
-
term-ansicolor (>= 1.0.6)
|
|
11
|
-
diff-lcs (1.1.3)
|
|
12
|
-
gherkin (2.7.7)
|
|
13
|
-
json (>= 1.4.6)
|
|
14
|
-
git (1.2.5)
|
|
15
|
-
jeweler (1.8.3)
|
|
16
|
-
bundler (~> 1.0)
|
|
17
|
-
git (>= 1.2.5)
|
|
18
|
-
rake
|
|
19
|
-
rdoc
|
|
20
|
-
json (1.6.5)
|
|
21
|
-
multi_json (1.0.4)
|
|
22
|
-
rake (0.9.2.2)
|
|
23
|
-
rdoc (3.12)
|
|
24
|
-
json (~> 1.4)
|
|
25
|
-
rspec (2.8.0)
|
|
26
|
-
rspec-core (~> 2.8.0)
|
|
27
|
-
rspec-expectations (~> 2.8.0)
|
|
28
|
-
rspec-mocks (~> 2.8.0)
|
|
29
|
-
rspec-core (2.8.0)
|
|
30
|
-
rspec-expectations (2.8.0)
|
|
31
|
-
diff-lcs (~> 1.1.2)
|
|
32
|
-
rspec-mocks (2.8.0)
|
|
33
|
-
simplecov (0.5.4)
|
|
34
|
-
multi_json (~> 1.0.3)
|
|
35
|
-
simplecov-html (~> 0.5.3)
|
|
36
|
-
simplecov-html (0.5.3)
|
|
37
|
-
term-ansicolor (1.0.7)
|
|
38
|
-
yard (0.7.5)
|
|
39
|
-
|
|
40
|
-
PLATFORMS
|
|
41
|
-
ruby
|
|
42
|
-
|
|
43
|
-
DEPENDENCIES
|
|
44
|
-
bundler (~> 1.0.0)
|
|
45
|
-
cucumber
|
|
46
|
-
jeweler (~> 1.8.3)
|
|
47
|
-
rdoc (~> 3.12)
|
|
48
|
-
rspec (~> 2.8.0)
|
|
49
|
-
simplecov
|
|
50
|
-
yard (~> 0.7)
|
data/README.rdoc
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
= zfstools
|
|
2
|
-
|
|
3
|
-
Various scripts for administrating ZFS. Modeled after OpenSolaris time-slider
|
|
4
|
-
|
|
5
|
-
== Contributing to zfstools
|
|
6
|
-
|
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
|
9
|
-
* Fork the project.
|
|
10
|
-
* Start a feature/bugfix branch.
|
|
11
|
-
* Commit and push until you are happy with your contribution.
|
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
|
14
|
-
|
|
15
|
-
== Copyright
|
|
16
|
-
|
|
17
|
-
Copyright (c) 2012-2013 Bryan Drewery. See LICENSE.txt for
|
|
18
|
-
further details.
|
data/Rakefile
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'rubygems'
|
|
4
|
-
require 'bundler'
|
|
5
|
-
begin
|
|
6
|
-
Bundler.setup(:default, :development)
|
|
7
|
-
rescue Bundler::BundlerError => e
|
|
8
|
-
$stderr.puts e.message
|
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
-
exit e.status_code
|
|
11
|
-
end
|
|
12
|
-
require 'rake'
|
|
13
|
-
|
|
14
|
-
require 'jeweler'
|
|
15
|
-
Jeweler::Tasks.new do |gem|
|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
|
-
gem.name = "zfstools"
|
|
18
|
-
gem.homepage = "http://github.com/bdrewery/zfstools"
|
|
19
|
-
gem.license = "BSD"
|
|
20
|
-
gem.summary = %Q{ZFSTools}
|
|
21
|
-
gem.description = %Q{ZFS admin scripts, such as automatic snapshots, mysql snapshotting, scrubbing, etc.}
|
|
22
|
-
gem.email = "bryan@shatow.net"
|
|
23
|
-
gem.authors = ["Bryan Drewery"]
|
|
24
|
-
# dependencies defined in Gemfile
|
|
25
|
-
end
|
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
|
27
|
-
|
|
28
|
-
require 'rspec/core'
|
|
29
|
-
require 'rspec/core/rake_task'
|
|
30
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
31
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
if RUBY_VERSION =~ /^1\.9/
|
|
35
|
-
desc "Code coverage detail"
|
|
36
|
-
task :simplecov do
|
|
37
|
-
ENV['COVERAGE'] = "true"
|
|
38
|
-
Rake::Task['spec'].execute
|
|
39
|
-
end
|
|
40
|
-
else
|
|
41
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
42
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
|
43
|
-
spec.rcov = true
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
require 'cucumber/rake/task'
|
|
48
|
-
Cucumber::Rake::Task.new(:features)
|
|
49
|
-
|
|
50
|
-
task :default => :spec
|
|
51
|
-
|
|
52
|
-
require 'yard'
|
|
53
|
-
YARD::Rake::YardocTask.new
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.2
|
|
File without changes
|
data/features/support/env.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require 'bundler'
|
|
2
|
-
begin
|
|
3
|
-
Bundler.setup(:default, :development)
|
|
4
|
-
rescue Bundler::BundlerError => e
|
|
5
|
-
$stderr.puts e.message
|
|
6
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
|
7
|
-
exit e.status_code
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
|
11
|
-
require 'zfstools'
|
|
12
|
-
|
|
13
|
-
require 'rspec/expectations'
|
data/features/zfstools.feature
DELETED
data/spec/spec_helper.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
|
-
|
|
4
|
-
if RUBY_VERSION =~ /^1\.9/
|
|
5
|
-
require 'simplecov'
|
|
6
|
-
|
|
7
|
-
module SimpleCov::Configuration
|
|
8
|
-
def clean_filters
|
|
9
|
-
@filters = []
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
SimpleCov.configure do
|
|
14
|
-
clean_filters
|
|
15
|
-
load_adapter 'test_frameworks'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
ENV["COVERAGE"] && SimpleCov.start do
|
|
19
|
-
add_filter "/.rvm/"
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
require 'rspec'
|
|
24
|
-
require 'zfstools'
|
|
25
|
-
|
|
26
|
-
# Requires supporting files with custom matchers and macros, etc,
|
|
27
|
-
# in ./support/ and its subdirectories.
|
|
28
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
29
|
-
|
|
30
|
-
RSpec.configure do |config|
|
|
31
|
-
|
|
32
|
-
end
|
data/spec/zfstools_spec.rb
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
-
|
|
3
|
-
describe "Zfstools", "#group_snapshots_into_datasets" do
|
|
4
|
-
it "Groups snapshots into their datasets" do
|
|
5
|
-
snapshots = {
|
|
6
|
-
'tank' => [
|
|
7
|
-
Zfs::Snapshot.new('tank@1'),
|
|
8
|
-
Zfs::Snapshot.new('tank@2'),
|
|
9
|
-
],
|
|
10
|
-
'tank/a' => [
|
|
11
|
-
Zfs::Snapshot.new('tank/a@1'),
|
|
12
|
-
Zfs::Snapshot.new('tank/a@2'),
|
|
13
|
-
],
|
|
14
|
-
'tank/a/1' => [
|
|
15
|
-
Zfs::Snapshot.new('tank/a/1@1'),
|
|
16
|
-
],
|
|
17
|
-
'tank/a/2' => [
|
|
18
|
-
Zfs::Snapshot.new('tank/a/2@1'),
|
|
19
|
-
],
|
|
20
|
-
'tank/b' => [
|
|
21
|
-
Zfs::Snapshot.new('tank/b@1'),
|
|
22
|
-
],
|
|
23
|
-
'tank/c' => [
|
|
24
|
-
Zfs::Snapshot.new('tank/c@1'),
|
|
25
|
-
],
|
|
26
|
-
'tank/d' => [
|
|
27
|
-
Zfs::Snapshot.new('tank/d@1'),
|
|
28
|
-
],
|
|
29
|
-
'tank/d/1' => [
|
|
30
|
-
Zfs::Snapshot.new('tank/d/1@2'),
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
datasets = {
|
|
34
|
-
'tank' => Zfs::Dataset.new('tank'),
|
|
35
|
-
'tank/a' => Zfs::Dataset.new('tank/a'),
|
|
36
|
-
'tank/a/1' => Zfs::Dataset.new('tank/a/1'),
|
|
37
|
-
'tank/a/2' => Zfs::Dataset.new('tank/a/2'),
|
|
38
|
-
'tank/b' => Zfs::Dataset.new('tank/b'),
|
|
39
|
-
'tank/c' => Zfs::Dataset.new('tank/c'),
|
|
40
|
-
'tank/d' => Zfs::Dataset.new('tank/d'),
|
|
41
|
-
'tank/d/1' => Zfs::Dataset.new('tank/d/1'),
|
|
42
|
-
}
|
|
43
|
-
dataset_snapshots = group_snapshots_into_datasets(snapshots.values.flatten, datasets.values)
|
|
44
|
-
dataset_snapshots.should eq({
|
|
45
|
-
datasets['tank'] => snapshots['tank'],
|
|
46
|
-
datasets['tank/a'] => snapshots['tank/a'],
|
|
47
|
-
datasets['tank/a/1'] => snapshots['tank/a/1'],
|
|
48
|
-
datasets['tank/a/2'] => snapshots['tank/a/2'],
|
|
49
|
-
datasets['tank/b'] => snapshots['tank/b'],
|
|
50
|
-
datasets['tank/c'] => snapshots['tank/c'],
|
|
51
|
-
datasets['tank/d'] => snapshots['tank/d'],
|
|
52
|
-
datasets['tank/d/1'] => snapshots['tank/d/1'],
|
|
53
|
-
})
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe "Zfstools", "#find_recursive_datasets" do
|
|
59
|
-
it "considers all included as recursive" do
|
|
60
|
-
tank = Zfs::Dataset.new("tank")
|
|
61
|
-
datasets = {
|
|
62
|
-
'included' => [
|
|
63
|
-
Zfs::Dataset.new("tank"),
|
|
64
|
-
Zfs::Dataset.new("tank/a"),
|
|
65
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
66
|
-
Zfs::Dataset.new("tank/b"),
|
|
67
|
-
],
|
|
68
|
-
'excluded' => [],
|
|
69
|
-
}
|
|
70
|
-
recursive_datasets = find_recursive_datasets(datasets)
|
|
71
|
-
recursive_datasets['recursive'].should eq([Zfs::Dataset.new("tank")])
|
|
72
|
-
recursive_datasets['single'].should eq([])
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "considers all multiple parent datasets as recursive" do
|
|
76
|
-
tank = Zfs::Dataset.new("tank")
|
|
77
|
-
datasets = {
|
|
78
|
-
'included' => [
|
|
79
|
-
Zfs::Dataset.new("tank"),
|
|
80
|
-
Zfs::Dataset.new("tank/a"),
|
|
81
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
82
|
-
Zfs::Dataset.new("tank/b"),
|
|
83
|
-
Zfs::Dataset.new("rpool"),
|
|
84
|
-
Zfs::Dataset.new("rpool/a"),
|
|
85
|
-
Zfs::Dataset.new("rpool/b"),
|
|
86
|
-
Zfs::Dataset.new("zpool"),
|
|
87
|
-
Zfs::Dataset.new("zpool/a"),
|
|
88
|
-
Zfs::Dataset.new("zpool/b"),
|
|
89
|
-
],
|
|
90
|
-
'excluded' => [],
|
|
91
|
-
}
|
|
92
|
-
recursive_datasets = find_recursive_datasets(datasets)
|
|
93
|
-
recursive_datasets['recursive'].should eq([
|
|
94
|
-
Zfs::Dataset.new("tank"),
|
|
95
|
-
Zfs::Dataset.new("rpool"),
|
|
96
|
-
Zfs::Dataset.new("zpool"),
|
|
97
|
-
])
|
|
98
|
-
recursive_datasets['single'].should eq([])
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it "considers all excluded as empty" do
|
|
102
|
-
tank = Zfs::Dataset.new("tank")
|
|
103
|
-
datasets = [
|
|
104
|
-
Zfs::Dataset.new("tank"),
|
|
105
|
-
Zfs::Dataset.new("tank/a"),
|
|
106
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
107
|
-
Zfs::Dataset.new("tank/b"),
|
|
108
|
-
]
|
|
109
|
-
included_excluded_datasets = {
|
|
110
|
-
'included' => [],
|
|
111
|
-
'excluded' => datasets,
|
|
112
|
-
}
|
|
113
|
-
recursive_datasets = find_recursive_datasets(included_excluded_datasets)
|
|
114
|
-
recursive_datasets['recursive'].should eq([])
|
|
115
|
-
recursive_datasets['single'].should eq([])
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it "considers first level excluded" do
|
|
119
|
-
included_excluded_datasets = {
|
|
120
|
-
'included' => [
|
|
121
|
-
Zfs::Dataset.new("tank"),
|
|
122
|
-
Zfs::Dataset.new("tank/a"),
|
|
123
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
124
|
-
],
|
|
125
|
-
'excluded' => [
|
|
126
|
-
Zfs::Dataset.new("rpool"),
|
|
127
|
-
Zfs::Dataset.new("rpool/a"),
|
|
128
|
-
]
|
|
129
|
-
}
|
|
130
|
-
recursive_datasets = find_recursive_datasets(included_excluded_datasets)
|
|
131
|
-
recursive_datasets['recursive'].should eq([
|
|
132
|
-
Zfs::Dataset.new("tank"),
|
|
133
|
-
])
|
|
134
|
-
recursive_datasets['single'].should eq([])
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "considers second level excluded" do
|
|
138
|
-
included_excluded_datasets = {
|
|
139
|
-
'included' => [
|
|
140
|
-
Zfs::Dataset.new("tank"),
|
|
141
|
-
Zfs::Dataset.new("tank/a"),
|
|
142
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
143
|
-
],
|
|
144
|
-
'excluded' => [
|
|
145
|
-
Zfs::Dataset.new("tank/b"),
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
recursive_datasets = find_recursive_datasets(included_excluded_datasets)
|
|
149
|
-
recursive_datasets['recursive'].should eq([
|
|
150
|
-
Zfs::Dataset.new("tank/a"),
|
|
151
|
-
])
|
|
152
|
-
recursive_datasets['single'].should eq([
|
|
153
|
-
Zfs::Dataset.new("tank"),
|
|
154
|
-
])
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "considers third level excluded" do
|
|
158
|
-
included_excluded_datasets = {
|
|
159
|
-
'included' => [
|
|
160
|
-
Zfs::Dataset.new("tank"),
|
|
161
|
-
Zfs::Dataset.new("tank/a"),
|
|
162
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
163
|
-
Zfs::Dataset.new("tank/a/2"),
|
|
164
|
-
Zfs::Dataset.new("tank/b"),
|
|
165
|
-
Zfs::Dataset.new("tank/b/1"),
|
|
166
|
-
Zfs::Dataset.new("tank/b/2"),
|
|
167
|
-
],
|
|
168
|
-
'excluded' => [
|
|
169
|
-
Zfs::Dataset.new("tank/c"),
|
|
170
|
-
]
|
|
171
|
-
}
|
|
172
|
-
recursive_datasets = find_recursive_datasets(included_excluded_datasets)
|
|
173
|
-
recursive_datasets['recursive'].should eq([
|
|
174
|
-
Zfs::Dataset.new("tank/a"),
|
|
175
|
-
Zfs::Dataset.new("tank/b"),
|
|
176
|
-
])
|
|
177
|
-
recursive_datasets['single'].should eq([
|
|
178
|
-
Zfs::Dataset.new("tank"),
|
|
179
|
-
])
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "considers child with mysql db in parent recursive" do
|
|
183
|
-
included_excluded_datasets = {
|
|
184
|
-
'included' => [
|
|
185
|
-
Zfs::Dataset.new("tank"),
|
|
186
|
-
Zfs::Dataset.new("tank/a"),
|
|
187
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
188
|
-
Zfs::Dataset.new("tank/a/2"),
|
|
189
|
-
Zfs::Dataset.new("tank/b"),
|
|
190
|
-
Zfs::Dataset.new("tank/b/1").contains_db!("mysql"),
|
|
191
|
-
Zfs::Dataset.new("tank/b/2"),
|
|
192
|
-
],
|
|
193
|
-
'excluded' => []
|
|
194
|
-
}
|
|
195
|
-
recursive_datasets = find_recursive_datasets(included_excluded_datasets)
|
|
196
|
-
recursive_datasets['recursive'].should eq([
|
|
197
|
-
Zfs::Dataset.new("tank").contains_db!("mysql"),
|
|
198
|
-
])
|
|
199
|
-
recursive_datasets['single'].should eq([])
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it "considers child with mysql db in recursive with singles and exclusions" do
|
|
203
|
-
included_excluded_datasets = {
|
|
204
|
-
'included' => [
|
|
205
|
-
Zfs::Dataset.new("tank"),
|
|
206
|
-
Zfs::Dataset.new("tank/a"),
|
|
207
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
208
|
-
Zfs::Dataset.new("tank/a/2").contains_db!("mysql"),
|
|
209
|
-
Zfs::Dataset.new("tank/b"),
|
|
210
|
-
Zfs::Dataset.new("tank/b/1"),
|
|
211
|
-
],
|
|
212
|
-
'excluded' => [
|
|
213
|
-
Zfs::Dataset.new("tank/b/2"),
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
recursive_datasets = find_recursive_datasets(included_excluded_datasets)
|
|
217
|
-
recursive_datasets['recursive'].should eq([
|
|
218
|
-
Zfs::Dataset.new("tank/a").contains_db!("mysql"),
|
|
219
|
-
Zfs::Dataset.new("tank/b/1"),
|
|
220
|
-
])
|
|
221
|
-
recursive_datasets['single'].should eq([
|
|
222
|
-
Zfs::Dataset.new("tank"),
|
|
223
|
-
Zfs::Dataset.new("tank/b"),
|
|
224
|
-
])
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
it "considers child with mysql db in single with recursives and exclusions" do
|
|
228
|
-
included_excluded_datasets = {
|
|
229
|
-
'included' => [
|
|
230
|
-
Zfs::Dataset.new("tank"),
|
|
231
|
-
Zfs::Dataset.new("tank/a"),
|
|
232
|
-
Zfs::Dataset.new("tank/a/1"),
|
|
233
|
-
Zfs::Dataset.new("tank/a/2"),
|
|
234
|
-
Zfs::Dataset.new("tank/b"),
|
|
235
|
-
Zfs::Dataset.new("tank/b/1").contains_db!("mysql"),
|
|
236
|
-
],
|
|
237
|
-
'excluded' => [
|
|
238
|
-
Zfs::Dataset.new("tank/b/2"),
|
|
239
|
-
]
|
|
240
|
-
}
|
|
241
|
-
recursive_datasets = find_recursive_datasets(included_excluded_datasets)
|
|
242
|
-
recursive_datasets['recursive'].should eq([
|
|
243
|
-
Zfs::Dataset.new("tank/a"),
|
|
244
|
-
Zfs::Dataset.new("tank/b/1").contains_db!("mysql"),
|
|
245
|
-
])
|
|
246
|
-
recursive_datasets['single'].should eq([
|
|
247
|
-
Zfs::Dataset.new("tank"),
|
|
248
|
-
Zfs::Dataset.new("tank/b"),
|
|
249
|
-
])
|
|
250
|
-
end
|
|
251
|
-
end
|
data/zfstools.gemspec
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
-
# -*- encoding: utf-8 -*-
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |s|
|
|
7
|
-
s.name = "zfstools"
|
|
8
|
-
s.version = "0.3.2"
|
|
9
|
-
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = ["Bryan Drewery"]
|
|
12
|
-
s.date = "2014-05-10"
|
|
13
|
-
s.description = "ZFS admin scripts, such as automatic snapshots, mysql snapshotting, scrubbing, etc."
|
|
14
|
-
s.email = "bryan@shatow.net"
|
|
15
|
-
s.executables = ["zfs-auto-snapshot", "zfs-cleanup-snapshots", "zfs-snapshot-mysql"]
|
|
16
|
-
s.extra_rdoc_files = [
|
|
17
|
-
"LICENSE.txt",
|
|
18
|
-
"README.md",
|
|
19
|
-
"README.rdoc"
|
|
20
|
-
]
|
|
21
|
-
s.files = [
|
|
22
|
-
".document",
|
|
23
|
-
".rspec",
|
|
24
|
-
"Gemfile",
|
|
25
|
-
"Gemfile.lock",
|
|
26
|
-
"LICENSE.txt",
|
|
27
|
-
"README.md",
|
|
28
|
-
"README.rdoc",
|
|
29
|
-
"Rakefile",
|
|
30
|
-
"VERSION",
|
|
31
|
-
"bin/zfs-auto-snapshot",
|
|
32
|
-
"bin/zfs-cleanup-snapshots",
|
|
33
|
-
"bin/zfs-snapshot-mysql",
|
|
34
|
-
"features/step_definitions/zfstools_steps.rb",
|
|
35
|
-
"features/support/env.rb",
|
|
36
|
-
"features/zfstools.feature",
|
|
37
|
-
"lib/zfstools.rb",
|
|
38
|
-
"lib/zfstools/dataset.rb",
|
|
39
|
-
"lib/zfstools/snapshot.rb",
|
|
40
|
-
"spec/spec_helper.rb",
|
|
41
|
-
"spec/zfstools_spec.rb",
|
|
42
|
-
"zfstools.gemspec"
|
|
43
|
-
]
|
|
44
|
-
s.homepage = "http://github.com/bdrewery/zfstools"
|
|
45
|
-
s.licenses = ["BSD"]
|
|
46
|
-
s.require_paths = ["lib"]
|
|
47
|
-
s.rubygems_version = "1.8.16"
|
|
48
|
-
s.summary = "ZFSTools"
|
|
49
|
-
|
|
50
|
-
if s.respond_to? :specification_version then
|
|
51
|
-
s.specification_version = 3
|
|
52
|
-
|
|
53
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
54
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
55
|
-
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
|
56
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
|
57
|
-
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
|
58
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
59
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
60
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
|
61
|
-
else
|
|
62
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
63
|
-
s.add_dependency(%q<yard>, ["~> 0.7"])
|
|
64
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
65
|
-
s.add_dependency(%q<cucumber>, [">= 0"])
|
|
66
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
67
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
68
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
69
|
-
end
|
|
70
|
-
else
|
|
71
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
72
|
-
s.add_dependency(%q<yard>, ["~> 0.7"])
|
|
73
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
74
|
-
s.add_dependency(%q<cucumber>, [">= 0"])
|
|
75
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
76
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
77
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|