snap-ebs 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/plugins/mongo_plugin.rb +4 -4
- data/lib/plugins/mysql_plugin.rb +76 -6
- data/lib/snap_ebs.rb +1 -0
- data/lib/snap_ebs/options.rb +5 -0
- data/lib/snap_ebs/snapshotter.rb +22 -12
- data/lib/snap_ebs/version.rb +3 -0
- metadata +11 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c62d36f1e86965f89d7733040c0ed8d6a70054be
|
4
|
+
data.tar.gz: 30e45d4efff41f0813b14a1a113b33daab257f41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d434a18fa189acf1ba449b49a6cce5e9058614c5cb35e0eb62c44a26ca9f43a34b0290122fa2b139134f2e8a8fd52d1883e2453b5fb258b54e6af6348f25efad
|
7
|
+
data.tar.gz: 089ba5066f153d6b1d8c542372c626d1dd17e8e9f251a719a7f6053bca980be34c0744fd23279f7ca0c4b0f0e8b9e06029d9d8054690d3d617256d4761de1f21
|
data/lib/plugins/mongo_plugin.rb
CHANGED
@@ -14,7 +14,7 @@ class SnapEbs::Plugin::MongoPlugin < SnapEbs::Plugin
|
|
14
14
|
host: 'Mongo host',
|
15
15
|
server_selection_timeout: 'Timeout in seconds while choosing a server to connect to (default 30)',
|
16
16
|
wait_queue_timeout: 'Timeout in seconds while waiting for a connection in the pool (default 1)',
|
17
|
-
|
17
|
+
connect_timeout: 'Timeout in seconds to wait for a socket to connect (default 5)',
|
18
18
|
socket_timeout: 'Timeout in seconds to wait for an operation to execute on a socket (default 5)'
|
19
19
|
}
|
20
20
|
end
|
@@ -29,7 +29,7 @@ class SnapEbs::Plugin::MongoPlugin < SnapEbs::Plugin
|
|
29
29
|
host: 'localhost',
|
30
30
|
server_selection_timeout: 30,
|
31
31
|
wait_queue_timeout: 1,
|
32
|
-
|
32
|
+
connect_timeout: 5,
|
33
33
|
socket_timeout: 5
|
34
34
|
}
|
35
35
|
end
|
@@ -65,7 +65,7 @@ class SnapEbs::Plugin::MongoPlugin < SnapEbs::Plugin
|
|
65
65
|
def unlock_or_start_mongo
|
66
66
|
(options.retry.to_i + 1).times do
|
67
67
|
if wired_tiger?
|
68
|
-
return if carefully('start mongo') { start_mongo }
|
68
|
+
return if options.shutdown && carefully('start mongo') { start_mongo }
|
69
69
|
else
|
70
70
|
return if carefully('unlock mongo') { unlock_mongo }
|
71
71
|
end
|
@@ -149,7 +149,7 @@ class SnapEbs::Plugin::MongoPlugin < SnapEbs::Plugin
|
|
149
149
|
password: options.password,
|
150
150
|
server_selection_timeout: options.server_selection_timeout.to_i,
|
151
151
|
wait_queue_timeout: options.wait_queue_timeout.to_i,
|
152
|
-
|
152
|
+
connect_timeout: options.connect_timeout.to_i,
|
153
153
|
socket_timeout: options.socket_timeout.to_i
|
154
154
|
}
|
155
155
|
end
|
data/lib/plugins/mysql_plugin.rb
CHANGED
@@ -1,22 +1,92 @@
|
|
1
1
|
class SnapEbs::Plugin::MysqlPlugin < SnapEbs::Plugin
|
2
2
|
def defined_options
|
3
3
|
{
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
shutdown: 'MySQL will only be shut down when this is set to "yes"',
|
5
|
+
username: 'MySQL Username',
|
6
|
+
password: 'MySQL Password',
|
7
|
+
port: 'MySQL port',
|
8
|
+
host: 'MySQL host'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def default_options
|
13
|
+
{
|
14
|
+
shutdown: 'no',
|
15
|
+
username: 'root',
|
16
|
+
password: 'root',
|
17
|
+
port: 3306,
|
18
|
+
host: 'localhost'
|
8
19
|
}
|
9
20
|
end
|
10
21
|
|
11
22
|
def before
|
12
|
-
require '
|
13
|
-
|
23
|
+
require 'mysql2'
|
24
|
+
if master?
|
25
|
+
logger.error "This appears to be a master in a replication set. Refusing to operate."
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
lock_tables
|
29
|
+
stop_mysql if options.shutdown == 'yes'
|
30
|
+
true
|
14
31
|
end
|
15
32
|
|
16
33
|
def after
|
34
|
+
if master?
|
35
|
+
logger.error "This appears to be a master in a replication set. Refusing to operate."
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
true
|
39
|
+
ensure
|
40
|
+
unlock_tables
|
41
|
+
start_mysql if options.shutdown == 'yes'
|
17
42
|
end
|
18
43
|
|
19
44
|
def name
|
20
45
|
"Mysql"
|
21
46
|
end
|
47
|
+
|
48
|
+
def client
|
49
|
+
@client ||= Mysql2::Client.new host: options.host, username: options.username, password: options.password, port: options.port
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def slave?
|
55
|
+
if @slave == nil
|
56
|
+
@slave = logger.debug client.query("SHOW SLAVE STATUS").to_a.any?
|
57
|
+
end
|
58
|
+
@slave
|
59
|
+
end
|
60
|
+
|
61
|
+
def lock_tables
|
62
|
+
client.query("FLUSH LOCAL TABLES")
|
63
|
+
client.query("FLUSH LOCAL TABLES WITH READ LOCK")
|
64
|
+
end
|
65
|
+
|
66
|
+
def unlock_tables
|
67
|
+
client.query("UNLOCK TABLES")
|
68
|
+
end
|
69
|
+
|
70
|
+
# > If you see no Binlog Dump threads on a master server, this means that
|
71
|
+
# > replication is not running—that is, that no slaves are currently
|
72
|
+
# > connected.
|
73
|
+
#
|
74
|
+
# https://dev.mysql.com/doc/refman/5.1/en/master-thread-states.html
|
75
|
+
def master?
|
76
|
+
if @master == nil
|
77
|
+
@master = client.query("SHOW PROCESSLIST").to_a.map { |x| x['Command'] }.include? 'Binlog Dump'
|
78
|
+
end
|
79
|
+
|
80
|
+
@master
|
81
|
+
end
|
82
|
+
|
83
|
+
def stop_mysql
|
84
|
+
# TODO
|
85
|
+
system("service mysql stop")
|
86
|
+
end
|
87
|
+
|
88
|
+
def start_mysql
|
89
|
+
# TODO
|
90
|
+
system("service mysql start")
|
91
|
+
end
|
22
92
|
end
|
data/lib/snap_ebs.rb
CHANGED
data/lib/snap_ebs/options.rb
CHANGED
@@ -42,6 +42,11 @@ class SnapEbs
|
|
42
42
|
o.on("-d", "--directory PATH", "Only snap volumes mounted to PATH, a comma-separated list of directories") do |d|
|
43
43
|
options.directory = d
|
44
44
|
end
|
45
|
+
|
46
|
+
o.on("", "--version", "Show version and exit") do |d|
|
47
|
+
puts "snap-ebs v#{::SnapEbs::VERSION}"
|
48
|
+
exit 0
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
plugins.each { |plugin| plugin.collect_options @option_parser }
|
data/lib/snap_ebs/snapshotter.rb
CHANGED
@@ -8,18 +8,28 @@ module SnapEbs::Snapshotter
|
|
8
8
|
# Takes snapshots of attached volumes (optionally filtering by volumes
|
9
9
|
# mounted to the given directories)
|
10
10
|
def take_snapshots
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
begin
|
12
|
+
system 'sync'
|
13
|
+
attached_volumes.each do |vol|
|
14
|
+
dir = device_to_directory device_name vol
|
15
|
+
fs_freeze dir if options[:fs_freeze]
|
16
|
+
next unless should_snap vol
|
17
|
+
logger.debug "Snapping #{vol.id}"
|
18
|
+
begin
|
19
|
+
snapshot = compute.snapshots.new
|
20
|
+
snapshot.volume_id = vol.id
|
21
|
+
snapshot.description = snapshot_name(vol)
|
22
|
+
snapshot.save
|
23
|
+
snapshot
|
24
|
+
rescue StandardError => e
|
25
|
+
logger.warn "Received error while snapping #{vol.id}:"
|
26
|
+
logger.warn e
|
27
|
+
end
|
28
|
+
fs_unfreeze dir if options[:fs_freeze]
|
29
|
+
end
|
30
|
+
rescue StandardError => e
|
31
|
+
logger.warn "Received error while walking volumes:"
|
32
|
+
logger.warn e
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snap-ebs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Conrad
|
@@ -14,56 +14,42 @@ dependencies:
|
|
14
14
|
name: fog
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.31'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.31'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: httparty
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.13'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.13'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: mysql
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2.9'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2.9'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: mongo
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - ~>
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '2.0'
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - ~>
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '2.0'
|
69
55
|
description: Tested, service-aware and consistent AWS EC2 backups via EBS snapshots.
|
@@ -81,6 +67,7 @@ files:
|
|
81
67
|
- lib/snap_ebs/options.rb
|
82
68
|
- lib/snap_ebs/plugin.rb
|
83
69
|
- lib/snap_ebs/snapshotter.rb
|
70
|
+
- lib/snap_ebs/version.rb
|
84
71
|
homepage: http://rubygems.org/gems/snap-ebs
|
85
72
|
licenses:
|
86
73
|
- MIT
|
@@ -91,17 +78,17 @@ require_paths:
|
|
91
78
|
- lib
|
92
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
80
|
requirements:
|
94
|
-
- -
|
81
|
+
- - ">="
|
95
82
|
- !ruby/object:Gem::Version
|
96
83
|
version: '0'
|
97
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
85
|
requirements:
|
99
|
-
- -
|
86
|
+
- - ">="
|
100
87
|
- !ruby/object:Gem::Version
|
101
88
|
version: '0'
|
102
89
|
requirements: []
|
103
90
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.4.
|
91
|
+
rubygems_version: 2.4.6
|
105
92
|
signing_key:
|
106
93
|
specification_version: 4
|
107
94
|
summary: EBS backups in a snap
|