sr-scripts 0.1.15 → 0.1.16
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.
- data/bin/sr-backup-mysql +2 -2
- data/bin/sr-detect-slaves +1 -1
- data/bin/sr-ec2-consistent-snapshot +6 -2
- data/bin/sr-promote-to-master +30 -9
- data/bin/sr-start-slave +11 -8
- data/lib/sr-scripts/version.rb +1 -1
- data/lib/sr-scripts.rb +24 -2
- metadata +3 -3
data/bin/sr-backup-mysql
CHANGED
@@ -6,10 +6,10 @@ require 'fog'
|
|
6
6
|
require 'mysql'
|
7
7
|
require 'sr-scripts'
|
8
8
|
|
9
|
-
connection = SrScripts::Compute.get
|
10
|
-
|
11
9
|
current_instance_id = `curl -s http://169.254.169.254/latest/meta-data/instance-id`
|
12
10
|
|
11
|
+
connection = SrScripts::Compute.find_connection(current_instance_id)
|
12
|
+
|
13
13
|
server = connection.servers.get(current_instance_id)
|
14
14
|
|
15
15
|
disks = server.tags["mysql_disks"].split(":")
|
data/bin/sr-detect-slaves
CHANGED
@@ -49,7 +49,7 @@ end
|
|
49
49
|
p "Found #{all_servers.length} Running Servers: " + all_servers.map {|s| s.id}.join(", ")
|
50
50
|
|
51
51
|
def print_server (server, padding)
|
52
|
-
printf "%#{padding}s: %
|
52
|
+
printf "%#{padding}s: %60s %s\n", server.id, server.created_at, server.dns_name
|
53
53
|
end
|
54
54
|
|
55
55
|
def print_all_slaves (server, all_servers, padding)
|
@@ -5,8 +5,10 @@
|
|
5
5
|
# A bunch of his features aren't ported over yet... just the stuff I needed.
|
6
6
|
|
7
7
|
require 'rubygems'
|
8
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
8
9
|
require 'optparse'
|
9
10
|
require 'fog'
|
11
|
+
require 'sr-scripts'
|
10
12
|
|
11
13
|
$opts = {
|
12
14
|
:aws_access_key => ENV["AWS_ACCESS_KEY_ID"],
|
@@ -49,6 +51,8 @@ if $opts[:aws_access_key].nil? || $opts[:aws_secret_access_key].nil?
|
|
49
51
|
exit 1
|
50
52
|
end
|
51
53
|
|
54
|
+
current_instance_id = `curl -s http://169.254.169.254/latest/meta-data/instance-id`
|
55
|
+
|
52
56
|
if ARGV.empty?
|
53
57
|
puts "You must provide at least one volume id to snapshot"
|
54
58
|
exit 1
|
@@ -118,7 +122,7 @@ end
|
|
118
122
|
snapshots = []
|
119
123
|
master_info = nil
|
120
124
|
|
121
|
-
connection =
|
125
|
+
connection = SrScripts::Compute.find_connection(current_instance_id)
|
122
126
|
sdb = Fog::AWS::SimpleDB.new(:aws_access_key_id => $opts[:aws_access_key], :aws_secret_access_key => $opts[:aws_secret_access_key])
|
123
127
|
begin
|
124
128
|
mysql_locked() do |info|
|
@@ -136,7 +140,7 @@ end
|
|
136
140
|
|
137
141
|
random_id = rand(36**8).to_s(36)
|
138
142
|
attributes = Hash.new
|
139
|
-
attributes["instance_id"] =
|
143
|
+
attributes["instance_id"] = current_instance_id
|
140
144
|
attributes["snapshots"] = snapshots.join(",")
|
141
145
|
attributes["timestamp"] = Time.now.to_i
|
142
146
|
attributes["master_log_file"] = master_info["MASTER_LOG_FILE"]
|
data/bin/sr-promote-to-master
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
4
5
|
require 'fog'
|
5
6
|
require 'mysql'
|
6
7
|
require 'optparse'
|
@@ -22,6 +23,9 @@ optparse = OptionParser.new do|opts|
|
|
22
23
|
opts.on( '--mysql-pass PASSWORD', 'Mysql Password') do |o|
|
23
24
|
options[:mysql_password] = o
|
24
25
|
end
|
26
|
+
opts.on( '--sns-topic-id TOPIC_ID', 'SNS Topic Id To Post To') do |o|
|
27
|
+
options[:sns_topic_id] = o
|
28
|
+
end
|
25
29
|
opts.on( '--skip-master', 'Use This Flag To Skip Connecting To --current-master-id') do |o|
|
26
30
|
options[:skip_master] = true
|
27
31
|
end
|
@@ -58,18 +62,21 @@ def get_public_ip(fog, instance_id)
|
|
58
62
|
return fog.servers.get(instance_id).public_ip_address
|
59
63
|
end
|
60
64
|
|
65
|
+
fog_current_master = connection.servers.get(options[:current_master_id])
|
66
|
+
fog_new_master = connection.servers.get(options[:new_master_id])
|
67
|
+
|
61
68
|
mysql_user = options[:mysql_user]
|
62
69
|
mysql_pass = options[:mysql_password]
|
63
70
|
|
64
71
|
current_master_ip = get_public_ip(connection, options[:current_master_id])
|
65
72
|
new_master_ip = get_public_ip(connection, options[:new_master_id])
|
66
73
|
|
67
|
-
|
74
|
+
current_master_mysql, new_master_mysql = nil
|
68
75
|
|
69
76
|
unless options[:skip_master]
|
70
77
|
begin
|
71
|
-
|
72
|
-
p
|
78
|
+
current_master_mysql = Mysql.new(current_master_ip, mysql_user, mysql_pass)
|
79
|
+
p current_master_mysql.query("SELECT version();")
|
73
80
|
rescue
|
74
81
|
puts "Error Connecting to --master-instance-id. Try running with --skip-master"
|
75
82
|
exit 1
|
@@ -77,18 +84,32 @@ unless options[:skip_master]
|
|
77
84
|
end
|
78
85
|
|
79
86
|
begin
|
80
|
-
|
87
|
+
new_master_mysql = Mysql.new(new_master_ip, mysql_user, mysql_pass)
|
81
88
|
rescue
|
82
89
|
puts "Error connecting to new master"
|
83
90
|
exit 1
|
84
91
|
end
|
85
92
|
|
86
93
|
unless options[:skip_master]
|
87
|
-
|
94
|
+
current_master_mysql.query("SET GLOBAL read_only = 1")
|
88
95
|
sleep 1 # HACKY CRAP
|
89
|
-
kill_mysql_connections
|
96
|
+
kill_mysql_connections current_master_mysql
|
90
97
|
end
|
91
|
-
|
92
|
-
|
98
|
+
new_master_mysql.query("STOP SLAVE;")
|
99
|
+
new_master_mysql.query("SET GLOBAL read_only = 0")
|
93
100
|
|
94
|
-
puts "
|
101
|
+
puts "New Master Set"
|
102
|
+
private_dns_alias = fog_new_master.tags["master_alias"]
|
103
|
+
if private_dns_alias
|
104
|
+
puts "Updating DNS Entries"
|
105
|
+
puts "Creating entry: #{private_dns_alias} #{fog_new_master.private_ip_address}"
|
106
|
+
SrScripts::HostsManager.new.update_dns(private_dns_alias, fog_new_master.private_ip_address)
|
107
|
+
public_dns_alias = "#{private_dns_alias}.external"
|
108
|
+
puts "Creating entry: #{public_dns_alias} #{fog_new_master.public_ip_address}"
|
109
|
+
SrScripts::HostsManager.new.update_dns(public_dns_alias, fog_new_master.public_ip_address)
|
110
|
+
if options[:sns_topic_id]
|
111
|
+
puts "POSTING MESSAGE TO SNS TOPIC: #{options[:sns_topic_id]}"
|
112
|
+
sns = SrScripts::SNS.get
|
113
|
+
sns.publish(options[:sns_topic_id], "ReloadHostsFile")
|
114
|
+
end
|
115
|
+
end
|
data/bin/sr-start-slave
CHANGED
@@ -7,22 +7,21 @@ require 'mysql'
|
|
7
7
|
require 'ostruct'
|
8
8
|
require 'sr-scripts'
|
9
9
|
|
10
|
-
|
10
|
+
instance_id = ARGV[0]
|
11
|
+
if ARGV.length != 1
|
12
|
+
p "Must specify an instance id"
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
connection = SrScripts::Compute.find_connection(instance_id)
|
11
17
|
sdb = SrScripts::SimpleDB.get
|
12
18
|
|
13
19
|
#STUPID HACK because the RPM install starts the server
|
14
20
|
`kill -9 $(ps opid= -C mysqld)`
|
15
21
|
|
16
22
|
# somewhere up here check to see if the devices are already attached
|
17
|
-
|
18
23
|
p connection.snapshots.all.first
|
19
24
|
|
20
|
-
if ARGV.length != 1
|
21
|
-
p "Must specify an instance id"
|
22
|
-
exit
|
23
|
-
end
|
24
|
-
|
25
|
-
instance_id = ARGV[0]
|
26
25
|
|
27
26
|
records = sdb.select("SELECT * FROM db_recovery_info WHERE instance_id = '#{instance_id}' AND timestamp > '1' ORDER BY timestamp DESC LIMIT 5").body["Items"]
|
28
27
|
|
@@ -63,6 +62,10 @@ end
|
|
63
62
|
|
64
63
|
#latest_snapshots now equals the snapshot ids
|
65
64
|
p latest_snapshots
|
65
|
+
if latest_snapshots == nil
|
66
|
+
puts "Exiting: Couldn't Find Any Available Snapshots To Use"
|
67
|
+
exit
|
68
|
+
end
|
66
69
|
|
67
70
|
def get_latest_snapshot(snapshots, instance_id)
|
68
71
|
filtered_snap = snapshots.find_all { |s| s.tags["instance_id"] == instance_id }
|
data/lib/sr-scripts/version.rb
CHANGED
data/lib/sr-scripts.rb
CHANGED
@@ -20,12 +20,26 @@ module SrScripts
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
class Compute
|
23
|
-
def self.get
|
23
|
+
def self.get region=nil
|
24
|
+
@region = region || 'us-west-1'
|
24
25
|
yml = ConfigFile.get
|
25
26
|
@aws_access_key = yml["aws_access_key"]
|
26
27
|
@aws_secret_key = yml["aws_secret_key"]
|
27
|
-
return Fog::Compute.new(:provider => "AWS", :aws_access_key_id => @aws_access_key, :aws_secret_access_key => @aws_secret_key, :region =>
|
28
|
+
return Fog::Compute.new(:provider => "AWS", :aws_access_key_id => @aws_access_key, :aws_secret_access_key => @aws_secret_key, :region => @region)
|
28
29
|
end
|
30
|
+
def self.find_connection(instance_id)
|
31
|
+
self.get_regions.each do |region|
|
32
|
+
conn = self.get(region)
|
33
|
+
server = conn.servers.get(instance_id)
|
34
|
+
if server
|
35
|
+
return conn
|
36
|
+
end
|
37
|
+
end
|
38
|
+
puts "Couldn't Find Server With Instance Id: #{instance_id}"
|
39
|
+
end
|
40
|
+
def self.get_regions
|
41
|
+
return ['us-west-1', 'us-west-2', 'us-east-1']
|
42
|
+
end
|
29
43
|
end
|
30
44
|
class SimpleDB
|
31
45
|
def self.get
|
@@ -43,6 +57,14 @@ module SrScripts
|
|
43
57
|
return Fog::AWS::SES.new(:aws_access_key_id => @aws_access_key, :aws_secret_access_key => @aws_secret_key)
|
44
58
|
end
|
45
59
|
end
|
60
|
+
class SNS
|
61
|
+
def self.get
|
62
|
+
yml = ConfigFile.get
|
63
|
+
@aws_access_key = yml["aws_access_key"]
|
64
|
+
@aws_secret_key = yml["aws_secret_key"]
|
65
|
+
return Fog::AWS::SNS.new(:aws_access_key_id => @aws_access_key, :aws_secret_access_key => @aws_secret_key, :region => 'us-east-1')
|
66
|
+
end
|
67
|
+
end
|
46
68
|
class Log
|
47
69
|
def self.get
|
48
70
|
@log = Logger.new(STDOUT)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 16
|
9
|
+
version: 0.1.16
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Davy Campano
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-03-
|
17
|
+
date: 2012-03-30 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|