mongodump 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +3 -0
- data/lib/mongodump.rb +18 -0
- data/lib/mongodump/db/base.rb +30 -0
- data/lib/mongodump/db/mongohq.rb +9 -0
- data/lib/mongodump/db/mongolab.rb +19 -0
- data/lib/mongodump/display.rb +15 -0
- data/lib/mongodump/dump.rb +36 -0
- data/lib/mongodump/heroku.rb +17 -0
- data/lib/mongodump/restore.rb +21 -0
- data/lib/mongodump/tasks.rb +11 -0
- data/lib/mongodump/tasks/mongodump.rake +22 -0
- data/lib/mongodump/version.rb +3 -0
- data/mongodump.gemspec +31 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eefdab898c9d2a880fef12058d5aa41c81fd7f54
|
4
|
+
data.tar.gz: fbb1188cd72b51c6b6d4823332a3056ebeb6a0d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b73fec32a71f27814236eb7dda451d1cee936877b4bceffaf9d391d63da56c79a159af8b72a8a122bcc49dee886795b4bce94bdd03533131bf487ad884d79095
|
7
|
+
data.tar.gz: 064e39dfdd4e2130f9a870c59b6561fdfb178e628a084e30836a9c1990887055841d5cfdf18690d5415c10c35aa98381f1f243fb7e6fafdb1b90ee027f6f7e25
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pierre FILSTROFF
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Mongodump
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mongodump'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mongodump
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/mongodump.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mongodump/heroku'
|
2
|
+
require 'mongodump/dump'
|
3
|
+
require 'mongodump/restore'
|
4
|
+
require 'mongodump/db/base'
|
5
|
+
require 'mongodump/db/mongolab'
|
6
|
+
require 'mongodump/display'
|
7
|
+
|
8
|
+
require 'debugger'
|
9
|
+
require 'rake'
|
10
|
+
require 'colorize'
|
11
|
+
|
12
|
+
if defined?(Rails)
|
13
|
+
# Require rake tasks
|
14
|
+
require "mongodump/tasks"
|
15
|
+
end
|
16
|
+
|
17
|
+
module Mongodump
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mongodump
|
2
|
+
module DB
|
3
|
+
class Base
|
4
|
+
attr_accessor :uri
|
5
|
+
attr_accessor :protocol
|
6
|
+
attr_accessor :username
|
7
|
+
attr_accessor :password
|
8
|
+
attr_accessor :hostname
|
9
|
+
attr_accessor :port
|
10
|
+
attr_accessor :appname
|
11
|
+
|
12
|
+
def initialize(arg)
|
13
|
+
if arg.is_a?(String)
|
14
|
+
@uri = arg
|
15
|
+
parse
|
16
|
+
else
|
17
|
+
raise IncompatibleArgumentException
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def has_all_attributes?
|
22
|
+
for variable in [@uri, @protocol, @username, @password, @hostname, @port, @appname]
|
23
|
+
if variable.blank?
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mongodump
|
2
|
+
module DB
|
3
|
+
class Mongolab < Base
|
4
|
+
def parse
|
5
|
+
splitted_uri = @uri.scan(/^(.*):\/\/(.*?):(.*?)@(.*?):(\d*)\/(.*?)$/i).flatten
|
6
|
+
|
7
|
+
if splitted_uri.size == 6
|
8
|
+
@protocol = splitted_uri[0]
|
9
|
+
@username = splitted_uri[1]
|
10
|
+
@password = splitted_uri[2]
|
11
|
+
@hostname = splitted_uri[3]
|
12
|
+
@port = splitted_uri[4]
|
13
|
+
@appname = splitted_uri[5]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mongodump
|
2
|
+
module Dump
|
3
|
+
@@dump_command = "mongodump"
|
4
|
+
|
5
|
+
# Dump the mongo database
|
6
|
+
# - db_object <Mongodump::DB::Base>
|
7
|
+
def self.process(db_object)
|
8
|
+
cmd = @@dump_command
|
9
|
+
cmd << " -h #{db_object.hostname}:#{db_object.port}"
|
10
|
+
cmd << " -d #{db_object.appname}"
|
11
|
+
cmd << " -u #{db_object.username}"
|
12
|
+
cmd << " -p #{db_object.password}"
|
13
|
+
cmd << " -o db/dump"
|
14
|
+
Display.info("Dumping mongo database...")
|
15
|
+
Display.info(cmd)
|
16
|
+
|
17
|
+
# Execute cmd
|
18
|
+
system(cmd)
|
19
|
+
|
20
|
+
dump_path = File.join("db/dump", db_object.appname)
|
21
|
+
|
22
|
+
if File.exists?(dump_path)
|
23
|
+
read_app_name = Mongoid.default_session.options[:database]
|
24
|
+
real_dump_path = File.join("db/dump", read_app_name)
|
25
|
+
|
26
|
+
FileUtils.rm_rf(real_dump_path) if File.exists?(real_dump_path)
|
27
|
+
FileUtils.mv(dump_path, real_dump_path)
|
28
|
+
|
29
|
+
if File.exists?(real_dump_path)
|
30
|
+
Display.success("Dump OK.")
|
31
|
+
return real_dump_path
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mongodump
|
2
|
+
module Heroku
|
3
|
+
@@heroku_config = "heroku config --shell"
|
4
|
+
|
5
|
+
def self.parse_config
|
6
|
+
config = `#{@@heroku_config}`
|
7
|
+
|
8
|
+
hash = Hash.new
|
9
|
+
for line in config.split("\n")
|
10
|
+
line_array = line.split("=")
|
11
|
+
hash[line_array.first.downcase.to_sym] = line_array.second
|
12
|
+
end
|
13
|
+
|
14
|
+
return hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mongodump
|
2
|
+
module Restore
|
3
|
+
@@restore_command = "mongorestore"
|
4
|
+
|
5
|
+
# Restore the mongo database
|
6
|
+
# - path <String>
|
7
|
+
# - appname <String>
|
8
|
+
def self.process(path)
|
9
|
+
cmd = @@restore_command
|
10
|
+
cmd << " -h localhost"
|
11
|
+
cmd << " #{path} "
|
12
|
+
Display.info("Restoring mongo database...")
|
13
|
+
Display.info(cmd)
|
14
|
+
|
15
|
+
# Execute cmd
|
16
|
+
system(cmd)
|
17
|
+
|
18
|
+
Display.success("Restoration OK.")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
if defined?(Rails) && Rails.version >= '3'
|
2
|
+
module Mongodump
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
rake_tasks do
|
5
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |file| load file }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
else
|
10
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |file| load file }
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'mongodump'
|
2
|
+
|
3
|
+
desc 'Mongodump main rake task'
|
4
|
+
task :mongodump => :environment do
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
# Nil object to store object instance outside the conditional block
|
8
|
+
db_object = nil
|
9
|
+
|
10
|
+
# Parse heroku config
|
11
|
+
args = Mongodump::Heroku.parse_config
|
12
|
+
|
13
|
+
if args.has_key?(:mongolab_uri)
|
14
|
+
uri = args[:mongolab_uri]
|
15
|
+
db_object = Mongodump::DB::Mongolab.new(uri)
|
16
|
+
end
|
17
|
+
|
18
|
+
if db_object && db_object.has_all_attributes?
|
19
|
+
path = Mongodump::Dump.process(db_object)
|
20
|
+
Mongodump::Restore.process(path)
|
21
|
+
end
|
22
|
+
end
|
data/mongodump.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mongodump/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mongodump"
|
8
|
+
spec.version = Mongodump::VERSION
|
9
|
+
spec.authors = ["Pierre FILSTROFF"]
|
10
|
+
spec.email = ["pfilstroff@gmail.com"]
|
11
|
+
spec.description = %q{Mongodump dump the remote mongolab or mongohq databases and fetch data to the local database}
|
12
|
+
spec.summary = %q{Mongo db dump to local database}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency("colorize", "= 0.5.8")
|
22
|
+
spec.add_dependency("mongo", "= 1.9.0")
|
23
|
+
spec.add_dependency("bson_ext", "= 1.9.0")
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "mongo"
|
28
|
+
spec.add_development_dependency "bson_ext"
|
29
|
+
spec.add_development_dependency "debugger"
|
30
|
+
spec.add_development_dependency "colorize"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongodump
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pierre FILSTROFF
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mongo
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.9.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bson_ext
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.9.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mongo
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bson_ext
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: debugger
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: colorize
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Mongodump dump the remote mongolab or mongohq databases and fetch data
|
140
|
+
to the local database
|
141
|
+
email:
|
142
|
+
- pfilstroff@gmail.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- .gitignore
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE.txt
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- lib/mongodump.rb
|
153
|
+
- lib/mongodump/db/base.rb
|
154
|
+
- lib/mongodump/db/mongohq.rb
|
155
|
+
- lib/mongodump/db/mongolab.rb
|
156
|
+
- lib/mongodump/display.rb
|
157
|
+
- lib/mongodump/dump.rb
|
158
|
+
- lib/mongodump/heroku.rb
|
159
|
+
- lib/mongodump/restore.rb
|
160
|
+
- lib/mongodump/tasks.rb
|
161
|
+
- lib/mongodump/tasks/mongodump.rake
|
162
|
+
- lib/mongodump/version.rb
|
163
|
+
- mongodump.gemspec
|
164
|
+
homepage: ''
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubyforge_project:
|
184
|
+
rubygems_version: 2.0.3
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: Mongo db dump to local database
|
188
|
+
test_files: []
|