mondupe 0.0.11 → 0.0.13
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/bin/mondupe +32 -4
- data/lib/mondupe.rb +15 -7
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0006b87e2549eb7f41df32766cae37b019cebcc1
|
4
|
+
data.tar.gz: b561adb1e93b78e98770265e48e0d57238972cdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3467656b563b145a23aec9f4fabf4366d45a319b618edc48f19eea9304fd04fe1795d122c5dd9255b2156d134668ba4ea6107da4c9ee7d667b741a709d7c39e6
|
7
|
+
data.tar.gz: 6233d1f9bee088940acf1b20b1e7b4783910898a1c22e65ab920e65a16c0a8ca82ddcb9cba4b1631d858e22753825aa3e27aa63966de3ec7c2b8f47d9ca40dde
|
data/bin/mondupe
CHANGED
@@ -22,7 +22,7 @@ opt_parser = OptionParser.new do |opt|
|
|
22
22
|
opt.separator " Requires -n [name] -a [ipaddress]"
|
23
23
|
opt.separator " restore - Restore a mongo dump that exists on a host"
|
24
24
|
opt.separator " Requires -n [name] -a [ipaddress]"
|
25
|
-
opt.separator " Optional -t [tmpdir]"
|
25
|
+
opt.separator " Optional -t [tmpdir] -u [mongo_username] -p [mongo_password] -c [mongo_authdb]"
|
26
26
|
opt.separator " expire - (coming soon) Reset the expiration days of a node"
|
27
27
|
opt.separator " Requires ( -n [name] || -d [id] || -a [ipaddress] ) -e [expire_days]"
|
28
28
|
opt.separator " list - (coming soon) List all mongo hosts."
|
@@ -70,6 +70,22 @@ opt_parser = OptionParser.new do |opt|
|
|
70
70
|
$options[:size] = size
|
71
71
|
end
|
72
72
|
|
73
|
+
opt.on("-n","--mongodbname","Database name to restore to") do |mongo_db_name|
|
74
|
+
$options[:mongo_db_name] = mongo_db_name
|
75
|
+
end
|
76
|
+
|
77
|
+
opt.on("-u","--mongouser","Username to authenticate to mongodb with") do |mongo_user|
|
78
|
+
$options[:mongo_user] = mongo_user
|
79
|
+
end
|
80
|
+
|
81
|
+
opt.on("-p","--mongopass","Password to authenticate to mongodb with") do |mongo_pass|
|
82
|
+
$options[:mongo_pass] = mongo_pass
|
83
|
+
end
|
84
|
+
|
85
|
+
opt.on("-c","--mongoauthdb","Database to authenticate against for mongo") do |mongo_auth_db|
|
86
|
+
$options[:mongo_auth_db] = mongo_auth_db
|
87
|
+
end
|
88
|
+
|
73
89
|
opt.on("-h","--help","help") do
|
74
90
|
puts opt_parser
|
75
91
|
end
|
@@ -81,6 +97,11 @@ opt_parser = OptionParser.new do |opt|
|
|
81
97
|
opt.separator " - MONDUPE_S3_BUCKET_NAME"
|
82
98
|
opt.separator " - MONDUPE_KEY_PAIR_NAME"
|
83
99
|
opt.separator ""
|
100
|
+
opt.separator " Optional: (no default)"
|
101
|
+
opt.separator " - MONGO_USER"
|
102
|
+
opt.separator " - MONGO_PASS"
|
103
|
+
opt.separator " - MONGO_AUTH_DB"
|
104
|
+
opt.separator ""
|
84
105
|
opt.separator " Optional: (have sane defaults)"
|
85
106
|
opt.separator " - MONDUPE_INSTANCE_IMAGE_ID"
|
86
107
|
opt.separator " - MONDUPE_CHEF_RUN_LIST"
|
@@ -89,6 +110,9 @@ opt_parser = OptionParser.new do |opt|
|
|
89
110
|
opt.separator " - MONDUPE_SSH_KEY"
|
90
111
|
opt.separator " - MONDUPE_SSH_USER"
|
91
112
|
opt.separator " - MONDUPE_DUMP_FILE_NAME"
|
113
|
+
opt.separator ""
|
114
|
+
opt.separator " Optional as ENV Variable. Must be specified via command line or ENV. No default."
|
115
|
+
opt.separator " - MONGO_DB_NAME"
|
92
116
|
end
|
93
117
|
|
94
118
|
opt_parser.parse!
|
@@ -101,6 +125,10 @@ instance_ipaddress = $options[:ipaddress] || nil
|
|
101
125
|
instance_id = $options[:id] || nil
|
102
126
|
dump_tmp_path = $options[:tmpdir] || '/tmp'
|
103
127
|
expire_days = $options[:expire_days] || 3
|
128
|
+
mongo_db_name = $options[:mongo_db_name] || ENV['MONGO_DB_NAME'] || nil
|
129
|
+
mongo_user = $options[:mongo_user] || ENV['MONGO_USER'] || nil
|
130
|
+
mongo_pass = $options[:mongo_pass] || ENV['MONGO_PASS'] || nil
|
131
|
+
mongo_auth_db = $options[:mongo_auth_db] || ENV['MONGO_AUTH_DB'] || nil
|
104
132
|
instance_count = 1
|
105
133
|
chef_run_list = ENV['MONDUPE_CHEF_RUN_LIST'] || ""
|
106
134
|
chef_environment = ENV['MONDUPE_CHEF_ENVIRONMENT'] || "default"
|
@@ -114,7 +142,7 @@ security_group = ENV['MONDUPE_SECURITY_GROUP'] || nil
|
|
114
142
|
s3_bucket_name = ENV['MONDUPE_S3_BUCKET_NAME'] || nil
|
115
143
|
dump_file_name = ENV['MONDUPE_DUMP_FILE_NAME'] || 'mongodb.dump.tgz'
|
116
144
|
knife_exec = ENV['MONDUPE_KNIFE_EXEC'] || 'knife'
|
117
|
-
instance_volume_size =
|
145
|
+
instance_volume_size = 60
|
118
146
|
|
119
147
|
case ARGV[0]
|
120
148
|
when "create"
|
@@ -125,7 +153,7 @@ when "create"
|
|
125
153
|
Mondupe.new.create_dns(instance_fqdn, route53_domain, instance)
|
126
154
|
Mondupe.new.bootstrap(instance_name, instance_fqdn, instance.ip_address, chef_environment, chef_identity_file, chef_run_list, ssh_user, knife_exec)
|
127
155
|
Mondupe.new.get_db_dump_from_s3(instance.ip_address, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
|
128
|
-
Mondupe.new.restore_db(instance.ip_address, dump_tmp_path, ssh_key, ssh_user, dump_file_name)
|
156
|
+
Mondupe.new.restore_db(instance.ip_address, dump_tmp_path, ssh_key, ssh_user, dump_file_name, mongo_db_name, mongo_user, mongo_pass, mongo_auth_db)
|
129
157
|
puts " - - - Total Run Time: #{((total_seconds % 3600) / 60).to_i}m #{((total_seconds % 3600) % 60).to_i}s - - -"
|
130
158
|
when "delete"
|
131
159
|
puts "delete mongo host"
|
@@ -138,7 +166,7 @@ when "dumps3"
|
|
138
166
|
Mondupe.new.get_db_dump_from_s3(instance_ipaddress, s3_bucket_name, dump_tmp_path, ssh_user, dump_file_name)
|
139
167
|
when "restore"
|
140
168
|
puts "Restoring mongo database from dump"
|
141
|
-
Mondupe.new.restore_db(instance_ipaddress, dump_tmp_path, ssh_key, ssh_user, dump_file_name)
|
169
|
+
Mondupe.new.restore_db(instance_ipaddress, dump_tmp_path, ssh_key, ssh_user, dump_file_name, mongo_db_name, mongo_user, mongo_pass, mongo_auth_db)
|
142
170
|
when "terminate"
|
143
171
|
puts "Marking instance for termination"
|
144
172
|
Mondupe.new.terminate_instance(instance_id)
|
data/lib/mondupe.rb
CHANGED
@@ -112,31 +112,39 @@ class Mondupe
|
|
112
112
|
puts "Download URL: #{download_url}"
|
113
113
|
puts "#{Time.now.to_s} - Starting download."
|
114
114
|
puts " Please wait..."
|
115
|
-
`ssh -i ~/.ssh/DevOps.pem #{ssh_user}@#{instance_ip} "sudo mkdir -p #{dump_tmp_path} &&
|
115
|
+
`ssh -i ~/.ssh/DevOps.pem #{ssh_user}@#{instance_ip} "sudo mkdir -p #{dump_tmp_path} && cd #{dump_tmp_path} && wget '#{download_url}' -O #{File.join(dump_tmp_path, dump_file_name)} 2&>1"`
|
116
116
|
puts "#{Time.now.to_s} - Download completed"
|
117
117
|
end
|
118
118
|
|
119
|
-
def
|
119
|
+
def add_user(instance_ip, username, password, database, roles)
|
120
|
+
#add db users here
|
121
|
+
end
|
122
|
+
|
123
|
+
def restore_db(instance_ip, dump_tmp_path, ssh_key, ssh_user, dump_file_name, mongo_db_name, mongo_user, mongo_pass, mongo_auth_db)
|
120
124
|
# Restore from the database dump
|
121
125
|
# TODO - Fail the process if any step fails
|
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
|
+
db_connect_string = "mongo #{mongo_db_name}"
|
128
|
+
db_connect_string << " -u \"#{mongo_user}\" -p \"#{mongo_pass}\"" if !mongo_user.nil? && !mongo_pass.nil?
|
129
|
+
db_connect_string << " --authenticationDatabase \"#{mongo_auth_db}\"" if !mongo_auth_db.nil?
|
122
130
|
puts "#{Time.now.to_s} - Dropping existing database"
|
123
|
-
`ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "echo 'db.dropDatabase()' |
|
131
|
+
`ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "echo 'db.dropDatabase()' | #{db_connect_string}"`
|
124
132
|
if $?.success? then puts "#{Time.now.to_s} - Database drop complete" else abort("Error dropping database") end
|
125
133
|
puts "Extracting database dump archive file..."
|
126
134
|
`ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "cd #{dump_tmp_path}; tar xf #{dump_file_name}"`
|
127
135
|
if $?.success? then puts "#{Time.now.to_s} - Extraction complete!" else abort("Error extracting archive") end
|
128
|
-
puts "Restoring Mongo Database from extracted dump: #{File.join(dump_tmp_path, "
|
129
|
-
`ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "time mongorestore #{File.join(dump_tmp_path, "
|
136
|
+
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}")}"`
|
130
138
|
if $?.success? then puts "#{Time.now.to_s} - Database restore complete!" else abort("Error restoring databse") end
|
131
139
|
puts "Removing database archive file"
|
132
140
|
`ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "rm -rf #{File.join(dump_tmp_path, dump_file_name)}"`
|
133
141
|
if $?.success? then puts "#{Time.now.to_s} - Archive removed!" else abort("Error removing archive") end
|
134
142
|
puts "#{Time.now.to_s} - Removing saved searches"
|
135
|
-
puts `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "
|
143
|
+
puts `ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "#{db_connect_string} --eval 'db.users.update({save_searches: {$ne: null}}, {$unset: {save_searches: \\"\\"}}, {multi: true})'"`
|
136
144
|
#Need to find a way to test the prior command as it does not return a success or fail like the other commands
|
137
145
|
#if $?.success? then puts "#{Time.now.to_s} - Saved searches removed" else abort("Error removing saved searches") end
|
138
146
|
puts "#{Time.now.to_s} - Cleaning up our mess..."
|
139
|
-
`ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "rm -rf #{File.join(dump_tmp_path,
|
147
|
+
`ssh -i #{ssh_key} #{ssh_user}@#{instance_ip} "rm -rf #{File.join(dump_tmp_path, "#{mongo_db_name}")}"`
|
140
148
|
if $?.success? then puts "#{Time.now.to_s} - Mess cleaned up!" else abort("Error cleaning up after myself...") end
|
141
149
|
end
|
142
150
|
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mondupe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philip Hutchins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.38'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.38'
|
27
27
|
description: Create an AWS EC2 node and restore a MongoDB dump to it from an AWS S3
|
@@ -44,12 +44,12 @@ require_paths:
|
|
44
44
|
- lib
|
45
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
@@ -59,4 +59,3 @@ signing_key:
|
|
59
59
|
specification_version: 4
|
60
60
|
summary: MonDupe
|
61
61
|
test_files: []
|
62
|
-
has_rdoc:
|