mongo-db-utils 0.0.9.2 → 0.0.9.3
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/.travis.yml +4 -0
- data/README.md +5 -2
- data/Rakefile +6 -0
- data/integration-test-env/README.md +3 -7
- data/lib/mongo-db-utils/config-loader.rb +3 -3
- data/lib/mongo-db-utils/console.rb +1 -1
- data/lib/mongo-db-utils/models/config.rb +4 -7
- data/lib/mongo-db-utils/tools/commands.rb +12 -5
- data/lib/mongo-db-utils/version.rb +1 -1
- data/spec/config_loader_spec.rb +1 -1
- data/spec/config_proxy_spec.rb +1 -1
- data/spec/models/config_spec.rb +9 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc200a0f72f693a50a790204198e16914ddf20de
|
4
|
+
data.tar.gz: 31ff2d8deacdb9cf0030e6a7b585f161e122d7b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fd93c8cd9e389d2e7be88a2fb5af007f2560a8fa74b0f2007c02b1679961db1e2316af8cbf7094d03a6db7a2258e161a994c3b9f9f19455d138c5df28230bfd
|
7
|
+
data.tar.gz: f8a8de001e8969aa30ba61ed75463bcac5b1e533090519e73e0ea2976dfe0ec8ea57397ec1b362082e8ab4fafff144993041e911229f8b19de7400580605c958
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# MongoDbUtils
|
2
2
|
|
3
|
+
[](https://travis-ci.org/edeustace/mongo-db-utils)
|
4
|
+
|
5
|
+
|
3
6
|
### !Current version 0.0.9.2 is in Beta - for a safer version use 0.0.9
|
4
7
|
|
5
8
|
A little gem that simplifies backing up and copying your mongo dbs.
|
@@ -27,7 +30,7 @@ And then execute:
|
|
27
30
|
|
28
31
|
## Limitatons
|
29
32
|
|
30
|
-
|
33
|
+
ruby >= 1.9.3
|
31
34
|
|
32
35
|
## Usage
|
33
36
|
Once you launch the console it'll provide you with a set of options - pretty self explanatory.
|
@@ -43,7 +46,7 @@ When it does backups it stores them in ````~/.mongo-db-utils/backups/````. The n
|
|
43
46
|
## Building source
|
44
47
|
|
45
48
|
#run console
|
46
|
-
bundle exec bin/mongo-db-utils console path_to/config.yml (optional)
|
49
|
+
bundle exec bin/mongo-db-utils console path_to/config.yml (optional - it defaults to ~/.mongo-db-utils/config.yml)
|
47
50
|
|
48
51
|
#install the gem locally
|
49
52
|
rake build
|
data/Rakefile
CHANGED
@@ -8,9 +8,7 @@ This is only really useful if you are working on the source code. If you're just
|
|
8
8
|
### Standalone DB
|
9
9
|
|
10
10
|
* init the environment `create_two_standalone_dbs` - this creates 2 mongod instances on 27018/27019
|
11
|
-
* To run the console go:
|
12
|
-
|
13
|
-
bundle exec bin/mongo-db-utils console integration-test-env/standalone/config.yml
|
11
|
+
* To run the console go: `bundle exec bin/mongo-db-utils console integration-test-env/standalone/config.yml`
|
14
12
|
|
15
13
|
* kill the environment `kill_processes standalone/.processes`
|
16
14
|
|
@@ -20,10 +18,8 @@ This is only really useful if you are working on the source code. If you're just
|
|
20
18
|
* `create_two_replica_sets`
|
21
19
|
* `replica_sets/rs_config` - you'll probably have to run this a few times
|
22
20
|
* `seed_replica_sets`
|
23
|
-
* run the console:
|
24
|
-
|
25
|
-
bundle exec bin/mongo-db-utils console integration-test-env/replica_sets/config.yml
|
21
|
+
* run the console: `bundle exec bin/mongo-db-utils console integration-test-env/replica_sets/config.yml`
|
26
22
|
|
27
23
|
* kill the environment `kill_processes replica_sets/.processes`
|
28
24
|
|
29
|
-
|
25
|
+
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'mongo-db-utils/models/bucket'
|
2
|
+
require 'mongo-db-utils/models/config'
|
3
|
+
require 'mongo-db-utils/models/db'
|
4
4
|
|
5
5
|
require 'yaml'
|
6
6
|
|
@@ -174,7 +174,7 @@ eos
|
|
174
174
|
def add_single_db
|
175
175
|
mongo_uri = ask("Mongo uri (eg: 'mongodb://user:pass@locahost:27017/db')")
|
176
176
|
new_uri = mongo_uri.to_s.strip
|
177
|
-
successful = @config.
|
177
|
+
successful = @config.add_single_db(new_uri)
|
178
178
|
|
179
179
|
say("bad uri!") unless successful
|
180
180
|
|
@@ -35,7 +35,7 @@ module MongoDbUtils
|
|
35
35
|
end
|
36
36
|
|
37
37
|
|
38
|
-
def
|
38
|
+
def add_single_db(uri)
|
39
39
|
add_db Db.new(uri)
|
40
40
|
end
|
41
41
|
|
@@ -57,23 +57,20 @@ module MongoDbUtils
|
|
57
57
|
!@buckets.find{ |b| b.to_s == bucket.to_s}.nil?
|
58
58
|
end
|
59
59
|
|
60
|
-
def to_s
|
61
|
-
"Config"
|
62
|
-
end
|
63
|
-
|
64
60
|
private
|
65
61
|
def save
|
66
62
|
@writer.save(self) unless @writer.nil?
|
67
63
|
end
|
68
64
|
|
69
65
|
def add_db(db)
|
66
|
+
raise "nil db" if db.nil?
|
70
67
|
@dbs = [] if @dbs.nil?
|
71
|
-
unless
|
68
|
+
unless already_contains(db)
|
72
69
|
@dbs << db
|
73
70
|
@dbs.sort!
|
74
71
|
save
|
75
72
|
end
|
76
|
-
@dbs.include?(db)
|
73
|
+
@dbs.include?(db)
|
77
74
|
end
|
78
75
|
|
79
76
|
end
|
@@ -4,6 +4,14 @@ module MongoDbUtils
|
|
4
4
|
|
5
5
|
module Tools
|
6
6
|
|
7
|
+
class ToolsException < RuntimeError
|
8
|
+
attr :cmd, :output
|
9
|
+
def initialize(cmd, output)
|
10
|
+
@cmd = cmd
|
11
|
+
@output =output
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
class BaseCmd
|
8
16
|
private
|
9
17
|
def self.o(key,value)
|
@@ -31,7 +39,6 @@ module MongoDbUtils
|
|
31
39
|
end
|
32
40
|
|
33
41
|
class Dump < BaseCmd
|
34
|
-
|
35
42
|
# create the cmd string that will be executed by the system
|
36
43
|
def self.cmd(host_and_port,db,output,username = "", password = "")
|
37
44
|
options = build_base_options(host_and_port,db,username,password)
|
@@ -43,9 +50,9 @@ module MongoDbUtils
|
|
43
50
|
def self.run(host_and_port,db,output,username="", password ="")
|
44
51
|
cmd_string = self.cmd(host_and_port,db,output,username,password)
|
45
52
|
puts "[Dump] run: #{cmd_string}"
|
46
|
-
`#{cmd_string}`
|
53
|
+
output = `#{cmd_string}`
|
54
|
+
raise ToolsException.new("#{cmd_string}", output) unless $?.to_i == 0
|
47
55
|
end
|
48
|
-
|
49
56
|
end
|
50
57
|
|
51
58
|
class Restore < BaseCmd
|
@@ -58,7 +65,8 @@ module MongoDbUtils
|
|
58
65
|
def self.run(host_and_port,db,source_folder,username="", password ="")
|
59
66
|
cmd_string = self.cmd(host_and_port,db,source_folder,username,password)
|
60
67
|
puts "[Restore] run: #{cmd_string}"
|
61
|
-
`#{cmd_string}`
|
68
|
+
output = `#{cmd_string}`
|
69
|
+
raise ToolsException.new("#{cmd_string}", output) unless $?.to_i == 0
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
@@ -75,6 +83,5 @@ module MongoDbUtils
|
|
75
83
|
@value.nil? || @value.empty?
|
76
84
|
end
|
77
85
|
end
|
78
|
-
|
79
86
|
end
|
80
87
|
end
|
data/spec/config_loader_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe MongoDbUtils do
|
|
21
21
|
it "should write a config correctly" do
|
22
22
|
path = ".tmp_path/config2.yml"
|
23
23
|
config = MongoDbUtils::ConfigLoader.new(path).config
|
24
|
-
config.
|
24
|
+
config.add_single_db("mongodb://localhost:27017/db")
|
25
25
|
loaded_config = YAML.load(File.open(path))
|
26
26
|
loaded_config.dbs[0].uri.should == config.dbs[0].uri
|
27
27
|
end
|
data/spec/config_proxy_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe MongoDbUtils::ConfigProxy do
|
|
23
23
|
|
24
24
|
it "should add a single db" do
|
25
25
|
db = HighLine::String.new("mongodb://localhost:27017/db ")
|
26
|
-
@config.
|
26
|
+
@config.add_single_db(db)
|
27
27
|
@config.dbs.length.should == 1
|
28
28
|
@config.dbs[0].uri.should == "mongodb://localhost:27017/db"
|
29
29
|
@config.dbs[0].uri.class.to_s.should == "String"
|
data/spec/models/config_spec.rb
CHANGED
@@ -22,20 +22,20 @@ describe MongoDbUtils::Model::Config do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should add a single db" do
|
25
|
-
@config.
|
25
|
+
@config.add_single_db( "mongodb://localhost:27017/db")
|
26
26
|
@config.dbs.length.should == 1
|
27
|
-
@config.
|
27
|
+
@config.add_single_db( "mongodb://localhost:27017/db2")
|
28
28
|
@config.dbs.length.should == 2
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should not add the db if its already there" do
|
32
|
-
@config.
|
33
|
-
@config.
|
32
|
+
@config.add_single_db( "mongodb://localhost:27017/db")
|
33
|
+
@config.add_single_db( "mongodb://localhost:27017/db")
|
34
34
|
@config.dbs.length.should == 1
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should remove a single db" do
|
38
|
-
@config.
|
38
|
+
@config.add_single_db( "mongodb://localhost:27017/db")
|
39
39
|
@config.dbs.length.should == 1
|
40
40
|
@config.remove_db(@config.dbs[0])
|
41
41
|
@config.dbs.length.should == 0
|
@@ -49,4 +49,8 @@ describe MongoDbUtils::Model::Config do
|
|
49
49
|
@config.dbs.length.should == 0
|
50
50
|
end
|
51
51
|
|
52
|
+
it "should throw an exception if add a nil db" do
|
53
|
+
expect { @config.add_single_db(nil)}.to raise_error
|
54
|
+
end
|
55
|
+
|
52
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo-db-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.9.
|
4
|
+
version: 0.0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- edeustace
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -145,6 +145,7 @@ extensions: []
|
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
147
|
- .gitignore
|
148
|
+
- .travis.yml
|
148
149
|
- Gemfile
|
149
150
|
- LICENSE
|
150
151
|
- README.md
|