mongolly 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mongolly +5 -4
- data/lib/mongolly.rb +0 -1
- data/lib/mongolly/snapshot_manager.rb +18 -2
- data/lib/mongolly/version.rb +1 -1
- metadata +3 -3
data/bin/mongolly
CHANGED
@@ -23,7 +23,7 @@ module Mongolly
|
|
23
23
|
db = Mongo::Connection.new( @db_config["host"], @db_config["port"] )
|
24
24
|
db['admin'].authenticate( @db_config["user"], @db_config["pass"] )
|
25
25
|
|
26
|
-
SnapshotManager.take_snapshots( db, @config["aws_access_key_id"], @config["
|
26
|
+
SnapshotManager.take_snapshots( db, @config["aws_access_key_id"], @config["aws_secret_access_key"], @db_config["region"], @db_config["volumes"] )
|
27
27
|
end
|
28
28
|
|
29
29
|
desc "clean", "removes snapshots older than the given data"
|
@@ -34,7 +34,7 @@ module Mongolly
|
|
34
34
|
|
35
35
|
puts " ** Cleaning snapshots older than #{max_age}"
|
36
36
|
|
37
|
-
ec2 = AWS::EC2.new(access_key_id: @config["aws_access_key_id"], secret_access_key: @config["
|
37
|
+
ec2 = AWS::EC2.new(access_key_id: @config["aws_access_key_id"], secret_access_key: @config["aws_secret_access_key"]).regions[@db_config["region"]]
|
38
38
|
ec2.snapshots.with_owner(:self).each do |snapshot|
|
39
39
|
unless snapshot.tags[:created_at].nil? || snapshot.tags[:backup_key].nil?
|
40
40
|
if Time.parse(snapshot.tags[:created_at]) < max_age
|
@@ -56,11 +56,12 @@ module Mongolly
|
|
56
56
|
port: nil,
|
57
57
|
user: nil,
|
58
58
|
pass: nil,
|
59
|
+
region: nil,
|
59
60
|
volumes: [nil]
|
60
61
|
}
|
61
62
|
},
|
62
63
|
aws_access_key_id: nil,
|
63
|
-
|
64
|
+
aws_secret_access_key: nil,
|
64
65
|
}
|
65
66
|
|
66
67
|
File.open( CONFIG_PATH, "w" ) do |f|
|
@@ -108,7 +109,7 @@ module Mongolly
|
|
108
109
|
end
|
109
110
|
|
110
111
|
def valid_config?
|
111
|
-
%w(aws_access_key_id
|
112
|
+
%w(aws_access_key_id aws_secret_access_key).each do |arg|
|
112
113
|
raise ArgumentError.new("#{arg} cannot be empty") if @config[arg].to_s.strip.empty?
|
113
114
|
end
|
114
115
|
return true
|
data/lib/mongolly.rb
CHANGED
@@ -3,14 +3,23 @@ require 'aws-sdk'
|
|
3
3
|
module Mongolly
|
4
4
|
class SnapshotManager
|
5
5
|
|
6
|
-
def self.take_snapshots(db, aws_key_id, aws_secret_key, volume_ids)
|
6
|
+
def self.take_snapshots(db, aws_key_id, aws_secret_key, region, volume_ids)
|
7
|
+
profile_levels = {}
|
8
|
+
|
7
9
|
unless db.locked?
|
8
10
|
puts " ** Locking Database"
|
11
|
+
db.database_names.each do |db_name|
|
12
|
+
level = db[db_name].profiling_level
|
13
|
+
if level != :off
|
14
|
+
profile_levels[db_name] = level
|
15
|
+
db[db_name].profiling_level = :off
|
16
|
+
end
|
17
|
+
end
|
9
18
|
db.lock!
|
10
19
|
end
|
11
20
|
|
12
21
|
begin
|
13
|
-
ec2 = AWS::EC2.new(access_key_id: aws_key_id, secret_access_key: aws_secret_key)
|
22
|
+
ec2 = AWS::EC2.new(access_key_id: aws_key_id, secret_access_key: aws_secret_key).regions[region]
|
14
23
|
backup_key = (0...8).map{65.+(rand(25)).chr}.join
|
15
24
|
|
16
25
|
puts " ** Starting Snapshot with key #{backup_key}"
|
@@ -28,6 +37,13 @@ module Mongolly
|
|
28
37
|
if db.locked?
|
29
38
|
puts " ** Unlocking Database"
|
30
39
|
db.unlock!
|
40
|
+
db.database_names.each do |db_name|
|
41
|
+
level = profile_levels[db_name]
|
42
|
+
unless level.nil? || level == :off
|
43
|
+
puts " ** Setting #{db_name} profile level to #{level.to_s}"
|
44
|
+
db[db_name].profiling_level = level
|
45
|
+
end
|
46
|
+
end
|
31
47
|
end
|
32
48
|
end
|
33
49
|
end
|
data/lib/mongolly/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongolly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
segments:
|
109
109
|
- 0
|
110
|
-
hash:
|
110
|
+
hash: 3409233611429320048
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
none: false
|
113
113
|
requirements:
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash:
|
119
|
+
hash: 3409233611429320048
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
122
|
rubygems_version: 1.8.24
|