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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mondupe.rb +15 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff88c3505fd4a307852ae8685f9f9ad8bb15c3b8
4
- data.tar.gz: 106b4f838fef4fe9ccb7df6c19a3a4f588da13d8
3
+ metadata.gz: dc78120740c79e0004d0229600494145ced3a460
4
+ data.tar.gz: 411facd28bd4a82f4ab275a0de75daf42cba72a8
5
5
  SHA512:
6
- metadata.gz: 25496dd68a2b805032a9f1fc9a7f4b14bec20d46607514f7d54c5fe6e2f363bb69fc8f4f78cda237243133438e23914f63e49c5c3a842b8c13a9074484207744
7
- data.tar.gz: efdd126b458627a5b25f71f7e1fc842d37cb88e55d1562aeaa56cf0429597d2526a983f33f121347c4c74695906a8f0e90cfac63c56a66e2dbb5a7de85466eda
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
- `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "echo 'db.dropDatabase()' | #{db_connect_string}"`
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
- `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "cd #{dump_tmp_path}; tar xf #{dump_file_name}"`
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
- `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "time mongorestore #{File.join(dump_tmp_path, "#{mongo_db_name}")}"`
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
- `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "rm -rf #{File.join(dump_tmp_path, dump_file_name)}"`
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
- `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "rm -rf #{File.join(dump_tmp_path, "#{mongo_db_name}")}"`
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mondupe
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
  - Philip Hutchins