snap-ebs 0.0.21 → 0.0.22

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
  SHA1:
3
- metadata.gz: 038e0d25b2351492bf303b74f04c5e5263036df1
4
- data.tar.gz: 6d4d2fec3684e3291dc2cc78c11eb5fc22c016a4
3
+ metadata.gz: c62d36f1e86965f89d7733040c0ed8d6a70054be
4
+ data.tar.gz: 30e45d4efff41f0813b14a1a113b33daab257f41
5
5
  SHA512:
6
- metadata.gz: 8de0823435ddeace70b1ba6cb8d55c0d46f9413e9bad0ab7bc972b44a2b6cc21f5a49ff56190430e6fa31974a3799e3e9633fa122319cd858f691109fc01f2bf
7
- data.tar.gz: 6f2fcbfdd89f34f712f1fe5775cba9a6a61d125c1406ad694e74279e1159a7b0a420fe6682bacc0abc4fe7720261febd44052eec1c9188a098c69cc7e2267ff9
6
+ metadata.gz: d434a18fa189acf1ba449b49a6cce5e9058614c5cb35e0eb62c44a26ca9f43a34b0290122fa2b139134f2e8a8fd52d1883e2453b5fb258b54e6af6348f25efad
7
+ data.tar.gz: 089ba5066f153d6b1d8c542372c626d1dd17e8e9f251a719a7f6053bca980be34c0744fd23279f7ca0c4b0f0e8b9e06029d9d8054690d3d617256d4761de1f21
@@ -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
- connection_timeout: 'Timeout in seconds to wait for a socket to connect (default 5)',
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
- connection_timeout: 5,
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 } if options.shutdown
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
- connection_timeout: options.connection_timeout.to_i,
152
+ connect_timeout: options.connect_timeout.to_i,
153
153
  socket_timeout: options.socket_timeout.to_i
154
154
  }
155
155
  end
@@ -1,22 +1,92 @@
1
1
  class SnapEbs::Plugin::MysqlPlugin < SnapEbs::Plugin
2
2
  def defined_options
3
3
  {
4
- user: 'MySql Username',
5
- pass: 'MySql Password',
6
- port: 'MySql port',
7
- host: 'MySql host'
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 'mysql'
13
- Mysql.new
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
@@ -4,6 +4,7 @@ require 'ostruct'
4
4
  require 'snap_ebs/options'
5
5
  require 'snap_ebs/snapshotter'
6
6
  require 'snap_ebs/plugin'
7
+ require 'snap_ebs/version'
7
8
 
8
9
  class SnapEbs
9
10
  include SnapEbs::Options
@@ -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 }
@@ -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
- system 'sync'
12
- attached_volumes.collect do |vol|
13
- dir = device_to_directory device_name vol
14
- fs_freeze dir if options[:fs_freeze]
15
- next unless should_snap vol
16
- logger.debug "Snapping #{vol.id}"
17
- snapshot = compute.snapshots.new
18
- snapshot.volume_id = vol.id
19
- snapshot.description = snapshot_name(vol)
20
- snapshot.save
21
- snapshot
22
- fs_unfreeze dir if options[:fs_freeze]
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
 
@@ -0,0 +1,3 @@
1
+ class SnapEbs
2
+ VERSION = '0.0.22'
3
+ end
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.21
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.3
91
+ rubygems_version: 2.4.6
105
92
  signing_key:
106
93
  specification_version: 4
107
94
  summary: EBS backups in a snap