ec2-consistent-snapshot-rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "right_aws", ">= 2.0.0"
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "shoulda", ">= 0"
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ gem "rcov", ">= 0"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ right_aws (2.0.0)
12
+ right_http_connection (>= 1.2.1)
13
+ right_http_connection (1.2.4)
14
+ shoulda (2.11.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.0.0)
21
+ jeweler (~> 1.5.2)
22
+ rcov
23
+ right_aws (>= 2.0.0)
24
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Zach Wily
2
+
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:
10
+
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.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = ec2-consistent-snapshot-rb
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ec2-consistent-snapshot-rb
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) 2010 Zach Wily. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "ec2-consistent-snapshot-rb"
16
+ gem.homepage = "http://github.com/zwily/ec2-consistent-snapshot-rb"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Takes EBS snapshots while locking MySQL and freezing XFS}
19
+ gem.description = %Q{Ported from ec2-consistent-snapshot (http://alestic.com/2009/09/ec2-consistent-snapshot)}
20
+ gem.email = "zach@zwily.com"
21
+ gem.authors = ["Zach Wily"]
22
+ end
23
+ Jeweler::RubygemsDotOrgTasks.new
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ task :default => :test
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "ec2-consistent-snapshot-rb #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This script was largely ported from ec2-consistent-snapshot written
4
+ # by Eric Hammond: http://alestic.com/2009/09/ec2-consistent-snapshot
5
+ # A bunch of his features aren't ported over yet... just the stuff I needed.
6
+
7
+ require 'rubygems'
8
+ require 'right_aws'
9
+ require 'optparse'
10
+
11
+ $opts = {
12
+ :aws_access_key => ENV["AWS_ACCESS_KEY_ID"],
13
+ :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
14
+ :aws_region => 'us-east-1',
15
+
16
+ :description => '',
17
+ :xfs_filesystem => nil,
18
+
19
+ :mysql => false,
20
+ :mysql_username => 'root',
21
+ :mysql_password => nil,
22
+ :mysql_host => '127.0.0.1',
23
+ :mysql_master_status_file => nil,
24
+ :mysql_slave_status_file => nil,
25
+ }
26
+
27
+ OptionParser.new do |o|
28
+ o.on("--aws-access-key ACCESS_KEY", "AWS Access Key") {|v| $opts[:aws_access_key] = v }
29
+ o.on("--aws-secret-access-key SECRET_KEY", "AWS Secret Access Key") {|v| $opts[:aws_secret_access_key] = v }
30
+ o.on("--aws-region REGION", "AWS Region") {|v| $opts[:aws_region] = v }
31
+ o.on("--description STRING", "The description for the snapshot") {|v| $opts[:description] = v }
32
+ o.on("--xfs-filesystem MOUNTPOINT", "Filesystem to be frozen during snapshot") {|v| $opts[:xfs_filesystem] = v }
33
+ o.on("--mysql", "Indicates that the volume has mysql") {|v| $opts[:mysql] = v }
34
+ o.on("--mysql-username USERNAME", "MySQL user to connect as") {|v| $opts[:mysql_username] = v }
35
+ o.on("--mysql-password PASSWORD", "MySQL password") {|v| $opts[:mysql_password] = v }
36
+ o.on("--mysql-host HOST", "MySQL host") {|v| $opts[:mysql_host] = v }
37
+ o.on("--mysql-master-status-file FILENAME", "File to store in snapshot with master status") {|v| $opts[:mysql_master_status_file] = v }
38
+ o.on("--mysql-slave-status-file FILENAME", "File to store in snapshot with slave status") {|v| $opts[:mysql_slave_status_file] = v }
39
+ end.parse!
40
+
41
+ if $opts[:aws_access_key].nil? || $opts[:aws_secret_access_key].nil?
42
+ puts "You must specify your Amazon credentials via --aws-access-key and --aws-secret_access-key"
43
+ exit 1
44
+ end
45
+
46
+ if ARGV.empty?
47
+ puts "You must provide at least one volume id to snapshot"
48
+ exit 1
49
+ end
50
+ volume_ids = ARGV
51
+
52
+ def mysql_locked(&block)
53
+ mysql = nil
54
+
55
+ if $opts[:mysql]
56
+ require 'mysql'
57
+ mysql = Mysql::new($opts[:mysql_host], $opts[:mysql_username], $opts[:mysql_password])
58
+ mysql.query("SET SQL_LOG_BIN=0")
59
+ mysql.query("FLUSH LOCAL TABLES")
60
+ mysql.query("FLUSH LOCAL TABLES WITH READ LOCK")
61
+
62
+ def query_result_string(mysql, query)
63
+ result = mysql.query(query)
64
+ string = ""
65
+ if result.num_rows() > 0
66
+ result.fetch_row.each_with_index do |value, i|
67
+ string << "#{result.fetch_field_direct(i).name}: #{value}\n"
68
+ end
69
+ end
70
+ string
71
+ end
72
+
73
+ if $opts[:mysql_slave_status_file]
74
+ File.open($opts[:mysql_slave_status_file], "w").puts query_result_string(mysql, "SHOW SLAVE STATUS")
75
+ end
76
+
77
+ if $opts[:mysql_master_status_file]
78
+ File.open($opts[:mysql_master_status_file], "w").puts query_result_string(mysql, "SHOW MASTER STATUS")
79
+ end
80
+
81
+ mysql.query("SET SQL_LOG_BIN=1")
82
+ end
83
+
84
+ yield
85
+
86
+ mysql.real_query("UNLOCK TABLES") if mysql
87
+ end
88
+
89
+ def xfs_frozen(&block)
90
+ system('xfs_freeze', '-f', $opts[:xfs_filesystem]) if $opts[:xfs_filesystem]
91
+ yield
92
+ system('xfs_freeze', '-u', $opts[:xfs_filesystem]) if $opts[:xfs_filesystem]
93
+ end
94
+
95
+ begin
96
+ mysql_locked() do
97
+ xfs_frozen() do
98
+ ec2 = RightAws::Ec2.new($opts[:aws_access_key], $opts[:aws_secret_access_key], :region => $opts[:aws_region])
99
+ volume_ids.each do |volume_id|
100
+ snapshot = ec2.create_snapshot(volume_id, $opts[:description])
101
+ puts "#{volume_id}: #{snapshot[:aws_id]}"
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,70 @@
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 = %q{ec2-consistent-snapshot-rb}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Zach Wily"]
12
+ s.date = %q{2010-12-29}
13
+ s.default_executable = %q{ec2-consistent-snapshot-rb}
14
+ s.description = %q{Ported from ec2-consistent-snapshot (http://alestic.com/2009/09/ec2-consistent-snapshot)}
15
+ s.email = %q{zach@zwily.com}
16
+ s.executables = ["ec2-consistent-snapshot-rb"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/ec2-consistent-snapshot-rb",
30
+ "ec2-consistent-snapshot-rb.gemspec",
31
+ "lib/.dummy",
32
+ "test/helper.rb",
33
+ "test/test_ec2-consistent-snapshot-rb.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/zwily/ec2-consistent-snapshot-rb}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Takes EBS snapshots while locking MySQL and freezing XFS}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_ec2-consistent-snapshot-rb.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<right_aws>, [">= 2.0.0"])
51
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<right_aws>, [">= 2.0.0"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<right_aws>, [">= 2.0.0"])
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
67
+ s.add_dependency(%q<rcov>, [">= 0"])
68
+ end
69
+ end
70
+
data/lib/.dummy ADDED
@@ -0,0 +1 @@
1
+ Jeweler doesn't like me not having a lib/ directory.
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'ec2-consistent-snapshot-rb'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestEc2ConsistentSnapshotRb < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ec2-consistent-snapshot-rb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Zach Wily
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-29 00:00:00 -07:00
19
+ default_executable: ec2-consistent-snapshot-rb
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: right_aws
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 15
31
+ segments:
32
+ - 2
33
+ - 0
34
+ - 0
35
+ version: 2.0.0
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ prerelease: false
40
+ name: shoulda
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ prerelease: false
54
+ name: bundler
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 23
61
+ segments:
62
+ - 1
63
+ - 0
64
+ - 0
65
+ version: 1.0.0
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ prerelease: false
70
+ name: jeweler
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 7
77
+ segments:
78
+ - 1
79
+ - 5
80
+ - 2
81
+ version: 1.5.2
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ prerelease: false
86
+ name: rcov
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirement: *id005
97
+ description: Ported from ec2-consistent-snapshot (http://alestic.com/2009/09/ec2-consistent-snapshot)
98
+ email: zach@zwily.com
99
+ executables:
100
+ - ec2-consistent-snapshot-rb
101
+ extensions: []
102
+
103
+ extra_rdoc_files:
104
+ - LICENSE.txt
105
+ - README.rdoc
106
+ files:
107
+ - .document
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.rdoc
112
+ - Rakefile
113
+ - VERSION
114
+ - bin/ec2-consistent-snapshot-rb
115
+ - ec2-consistent-snapshot-rb.gemspec
116
+ - lib/.dummy
117
+ - test/helper.rb
118
+ - test/test_ec2-consistent-snapshot-rb.rb
119
+ has_rdoc: true
120
+ homepage: http://github.com/zwily/ec2-consistent-snapshot-rb
121
+ licenses:
122
+ - MIT
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ requirements: []
147
+
148
+ rubyforge_project:
149
+ rubygems_version: 1.3.7
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Takes EBS snapshots while locking MySQL and freezing XFS
153
+ test_files:
154
+ - test/helper.rb
155
+ - test/test_ec2-consistent-snapshot-rb.rb