mongodb_clone 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/CHANGELOG.md +7 -0
- data/README.md +3 -1
- data/gemfiles/rails-3.2.gemfile +6 -0
- data/gemfiles/rails-master.gemfile +5 -0
- data/lib/mongodb_clone.rb +1 -57
- data/lib/mongodb_clone/mongodb_replication.rb +65 -0
- data/lib/mongodb_clone/version.rb +1 -1
- data/mongodb_clone.gemspec +3 -2
- data/spec/{mongodb_clone_spec.rb → mongodb_clone/mongodb_replication_spec.rb} +10 -3
- data/spec/spec_helper.rb +3 -0
- metadata +28 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ae29dd49d07ae0d1205b4950bca9555bd7f875
|
4
|
+
data.tar.gz: 9aa9407029c673763bea5729a067f24c27b3516e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77a1faab44783fcb5b67be51c6d0d03f20953b914555532b8ecc74968d6792616275370b04f98cc04db2cfc5ffe390e9c8f1653c33e49ee964ef58ae707dec7d
|
7
|
+
data.tar.gz: 092e76b892e28000175a01aa96dc9cc0b77feccd7a3219c8c86250291f6ed2994ab777deef79d0999ad672f2f4d8ac5d237c7612f48462706e538dd4901ba0cb
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# MongodbClone
|
1
|
+
# MongodbClone [![Build Status](https://travis-ci.org/tiagogodinho/mongodb_clone.png?branch=master)](https://travis-ci.org/tiagogodinho/mongodb_clone) [![Dependency Status](https://gemnasium.com/tiagogodinho/mongodb_clone.png)](https://gemnasium.com/tiagogodinho/mongodb_clone) [![Gem Version](https://badge.fury.io/rb/mongodb_clone.png)](http://badge.fury.io/rb/mongodb_clone)
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/tiagogodinho/mongodb_clone.png)](https://codeclimate.com/github/tiagogodinho/mongodb_clone) [![Coverage Status](https://coveralls.io/repos/tiagogodinho/mongodb_clone/badge.png)](https://coveralls.io/r/tiagogodinho/mongodb_clone)
|
2
4
|
|
3
5
|
Dump and restore databases easily.
|
4
6
|
|
data/lib/mongodb_clone.rb
CHANGED
@@ -1,63 +1,7 @@
|
|
1
1
|
require 'rails'
|
2
|
+
require 'mongodb_clone/mongodb_replication'
|
2
3
|
require 'mongodb_clone/engine'
|
3
4
|
require 'mongodb_clone/version'
|
4
5
|
|
5
6
|
module MongodbClone
|
6
|
-
class MongodbReplication
|
7
|
-
attr_accessor :id, :path
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@id = Time.now.utc.strftime('%Y%m%d%H%M%S')
|
11
|
-
end
|
12
|
-
|
13
|
-
def dump(environment = 'production', session = 'default')
|
14
|
-
config = base_config[environment.to_s]['sessions'][session.to_s]
|
15
|
-
|
16
|
-
params = {
|
17
|
-
h: config['hosts'][0],
|
18
|
-
d: config['database'],
|
19
|
-
u: config['username'],
|
20
|
-
p: config['password'],
|
21
|
-
o: "/tmp/#{ config['database'] }/#{ @id }"
|
22
|
-
}
|
23
|
-
|
24
|
-
a = params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ')
|
25
|
-
|
26
|
-
command = "mongodump #{ a }"
|
27
|
-
|
28
|
-
execute(command)
|
29
|
-
|
30
|
-
@path = "#{ params[:o] }/#{ params[:d] }"
|
31
|
-
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def restore(environment = 'development', session = 'default')
|
36
|
-
config = base_config[environment.to_s]['sessions'][session.to_s]
|
37
|
-
|
38
|
-
params = {
|
39
|
-
h: config['hosts'][0],
|
40
|
-
d: config['database'],
|
41
|
-
u: config['username'],
|
42
|
-
p: config['password']
|
43
|
-
}
|
44
|
-
|
45
|
-
a = params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ')
|
46
|
-
|
47
|
-
command = "mongorestore --drop #{ a } #{ @path }"
|
48
|
-
|
49
|
-
execute(command)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def base_config
|
55
|
-
YAML.load_file(Rails.root.join('config/mongoid.yml'))
|
56
|
-
end
|
57
|
-
|
58
|
-
def execute(command)
|
59
|
-
puts command
|
60
|
-
`#{ command }`
|
61
|
-
end
|
62
|
-
end
|
63
7
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module MongodbClone
|
4
|
+
class MongodbReplication
|
5
|
+
attr_accessor :id, :path
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@id = Time.now.utc.strftime('%Y%m%d%H%M%S')
|
9
|
+
end
|
10
|
+
|
11
|
+
def dump(environment = 'production', session = 'default')
|
12
|
+
config = get_config(environment, session)
|
13
|
+
|
14
|
+
params = default_params(config).merge({ o: "/tmp/#{ config['database'] }/#{ @id }" })
|
15
|
+
|
16
|
+
a = hash_to_inline_params(params)
|
17
|
+
|
18
|
+
command = "mongodump #{ a }"
|
19
|
+
|
20
|
+
execute(command)
|
21
|
+
|
22
|
+
@path = "#{ params[:o] }/#{ params[:d] }"
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def restore(environment = 'development', session = 'default')
|
28
|
+
config = get_config(environment, session)
|
29
|
+
|
30
|
+
a = hash_to_inline_params(default_params(config))
|
31
|
+
|
32
|
+
command = "mongorestore --drop #{ a } #{ @path }"
|
33
|
+
|
34
|
+
execute(command)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def default_params(config)
|
40
|
+
{
|
41
|
+
h: config['hosts'][0],
|
42
|
+
d: config['database'],
|
43
|
+
u: config['username'],
|
44
|
+
p: config['password']
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_config(environment, session)
|
49
|
+
base_config[environment.to_s]['sessions'][session.to_s]
|
50
|
+
end
|
51
|
+
|
52
|
+
def hash_to_inline_params(params)
|
53
|
+
params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ')
|
54
|
+
end
|
55
|
+
|
56
|
+
def base_config
|
57
|
+
YAML.load_file(Rails.root.join('config/mongoid.yml'))
|
58
|
+
end
|
59
|
+
|
60
|
+
def execute(command)
|
61
|
+
puts command
|
62
|
+
`#{ command }`
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/mongodb_clone.gemspec
CHANGED
@@ -12,9 +12,10 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = %q{Write a gem summary}
|
13
13
|
gem.homepage = ''
|
14
14
|
|
15
|
-
gem.add_dependency '
|
15
|
+
gem.add_dependency 'railties', '>= 3.2.0'
|
16
16
|
|
17
|
-
gem.add_development_dependency '
|
17
|
+
gem.add_development_dependency 'coveralls', '~> 0.7'
|
18
|
+
gem.add_development_dependency 'rspec', '~> 2.14.0'
|
18
19
|
|
19
20
|
gem.files = `git ls-files`.split($/)
|
20
21
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -2,10 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MongodbClone::MongodbReplication do
|
4
4
|
before do
|
5
|
-
|
5
|
+
file = File.join(File.dirname(__FILE__), '../', 'support', 'mongoid.yml')
|
6
|
+
Rails.stub_chain(:root, :join).and_return(file)
|
6
7
|
end
|
7
8
|
|
9
|
+
subject { MongodbClone::MongodbReplication.new.as_null_object }
|
10
|
+
|
8
11
|
describe '#dump' do
|
12
|
+
it 'returns the object to create a chain of methods' do
|
13
|
+
subject.stub(:execute)
|
14
|
+
expect(subject.dump).to be_an_instance_of(described_class)
|
15
|
+
end
|
16
|
+
|
9
17
|
it 'should dump database' do
|
10
18
|
subject.id = '201210231843100200'
|
11
19
|
subject.should_receive(:execute).with('mongodump -h "mongodb_clone.example.com:27017" -d "mongodb_clone_production" -u "mongodb_clone" -p "12345678" -o "/tmp/mongodb_clone_production/201210231843100200"')
|
@@ -27,10 +35,9 @@ describe MongodbClone::MongodbReplication do
|
|
27
35
|
it 'should restore database' do
|
28
36
|
subject.id = '201210231843100200'
|
29
37
|
subject.path = '/tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production'
|
30
|
-
subject.should_receive(:execute).with('mongodump -h "mongodb_clone.example.com:27017" -d "mongodb_clone_production" -u "mongodb_clone" -p "12345678" -o "/tmp/mongodb_clone_production/201210231843100200"')
|
31
38
|
subject.should_receive(:execute).with('mongorestore --drop -h "localhost:27017" -d "mongodb_clone_development" /tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production')
|
32
39
|
|
33
|
-
subject.
|
40
|
+
subject.restore
|
34
41
|
end
|
35
42
|
end
|
36
43
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongodb_clone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Rafael Godinho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.0
|
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: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ~>
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
47
|
+
version: 2.14.0
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
54
|
+
version: 2.14.0
|
41
55
|
description: Write a gem description
|
42
56
|
email:
|
43
57
|
- tiagogodinho3@gmail.com
|
@@ -47,17 +61,21 @@ extra_rdoc_files: []
|
|
47
61
|
files:
|
48
62
|
- .gitignore
|
49
63
|
- .rspec
|
64
|
+
- .travis.yml
|
50
65
|
- CHANGELOG.md
|
51
66
|
- Gemfile
|
52
67
|
- LICENSE.txt
|
53
68
|
- README.md
|
54
69
|
- Rakefile
|
70
|
+
- gemfiles/rails-3.2.gemfile
|
71
|
+
- gemfiles/rails-master.gemfile
|
55
72
|
- lib/mongodb_clone.rb
|
56
73
|
- lib/mongodb_clone/engine.rb
|
74
|
+
- lib/mongodb_clone/mongodb_replication.rb
|
57
75
|
- lib/mongodb_clone/version.rb
|
58
76
|
- lib/tasks/mongodb_clone.rake
|
59
77
|
- mongodb_clone.gemspec
|
60
|
-
- spec/
|
78
|
+
- spec/mongodb_clone/mongodb_replication_spec.rb
|
61
79
|
- spec/spec_helper.rb
|
62
80
|
- spec/support/mongoid.yml
|
63
81
|
homepage: ''
|
@@ -79,11 +97,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
97
|
version: '0'
|
80
98
|
requirements: []
|
81
99
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.1.10
|
83
101
|
signing_key:
|
84
102
|
specification_version: 4
|
85
103
|
summary: Write a gem summary
|
86
104
|
test_files:
|
87
|
-
- spec/
|
105
|
+
- spec/mongodb_clone/mongodb_replication_spec.rb
|
88
106
|
- spec/spec_helper.rb
|
89
107
|
- spec/support/mongoid.yml
|