mondupe 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 +4 -4
- data/lib/mondupe.rb +15 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc78120740c79e0004d0229600494145ced3a460
|
4
|
+
data.tar.gz: 411facd28bd4a82f4ab275a0de75daf42cba72a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c23948d38c775187131f6f203d715f23c47fb762fc03c59b0f6e26efe67870de6b13953a76b600fc654f81edbb21d2dde1048b33f47a135d7ccb5b903f14b06
|
7
|
+
data.tar.gz: cf5806525cec2fed74d65e99192e9aeafa054e93d2c55a9465395bdb1fd6911c7a56dcb2914d2db4759696624cde7d8a14574436261c5750bf3ffb650ed8b655
|
data/lib/mondupe.rb
CHANGED
@@ -124,23 +124,33 @@ class Mondupe
|
|
124
124
|
# Restore from the database dump
|
125
125
|
# TODO - Fail the process if any step fails
|
126
126
|
abort "You must specify a database name to drop and restore. Use -n [name] or ENV['MONGO_DB_NAME'] to set this value." if mongo_db_name.nil?
|
127
|
+
ssh_command = "ssh -i #{ssh_key} #{ssh_user}@#{instance_ip}"
|
127
128
|
db_connect_string = "mongo #{mongo_db_name}"
|
128
129
|
db_connect_string << " -u \"#{mongo_user}\" -p \"#{mongo_pass}\"" if !mongo_user.nil? && !mongo_pass.nil?
|
129
130
|
db_connect_string << " --authenticationDatabase \"#{mongo_auth_db}\"" if !mongo_auth_db.nil?
|
131
|
+
tries = 20
|
132
|
+
begin
|
133
|
+
`#{ssh_command} "echo 'db.serverStatus()' | #{db_connect_string}"` or raise "Connection failed..."
|
134
|
+
sleep 20
|
135
|
+
rescue
|
136
|
+
tries -= 1
|
137
|
+
puts "Could not connect to DB. Trying again... #{tries} left."
|
138
|
+
retry if tries > 0
|
139
|
+
end
|
130
140
|
puts "#{Time.now.to_s} - Dropping existing database"
|
131
|
-
|
141
|
+
`#{ssh_command} "echo 'db.dropDatabase()' | #{db_connect_string}"`
|
132
142
|
if $?.success? then puts "#{Time.now.to_s} - Database drop complete" else abort("Error dropping database") end
|
133
143
|
puts "Extracting database dump archive file..."
|
134
|
-
|
144
|
+
`#{ssh_command} cd #{dump_tmp_path}; tar xf #{dump_file_name}"`
|
135
145
|
if $?.success? then puts "#{Time.now.to_s} - Extraction complete!" else abort("Error extracting archive") end
|
136
146
|
puts "Restoring Mongo Database from extracted dump: #{File.join(dump_tmp_path, "#{mongo_db_name}")}"
|
137
|
-
|
147
|
+
`#{ssh_command} "time mongorestore #{File.join(dump_tmp_path, "#{mongo_db_name}")}"`
|
138
148
|
if $?.success? then puts "#{Time.now.to_s} - Database restore complete!" else abort("Error restoring databse") end
|
139
149
|
puts "Removing database archive file"
|
140
|
-
|
150
|
+
`#{ssh_command} "rm -rf #{File.join(dump_tmp_path, dump_file_name)}"`
|
141
151
|
if $?.success? then puts "#{Time.now.to_s} - Archive removed!" else abort("Error removing archive") end
|
142
152
|
puts "#{Time.now.to_s} - Cleaning up our mess..."
|
143
|
-
|
153
|
+
`#{ssh_command} "rm -rf #{File.join(dump_tmp_path, "#{mongo_db_name}")}"`
|
144
154
|
if $?.success? then puts "#{Time.now.to_s} - Mess cleaned up!" else abort("Error cleaning up after myself...") end
|
145
155
|
end
|
146
156
|
|