Class: Dumper::Database::MongoDB
- Inherits:
-
Base
- Object
- Base
- Dumper::Database::MongoDB
show all
- Defined in:
- lib/dumper/database/mongodb.rb
Constant Summary
collapse
- DUMP_TOOL =
'mongodump'
- FILE_EXT =
'tar.gz'
Instance Attribute Summary
Attributes inherited from Base
#filename, #tmpdir
Instance Method Summary
collapse
Methods inherited from Base
#dump_path, #dump_tool_path, #file_ext, #finalize, #initialize
#find_instance_in_object_space
Instance Method Details
#additional_options ⇒ Object
18
19
20
|
# File 'lib/dumper/database/mongodb.rb', line 18
def additional_options
"--out='#{tmpdir}'"
end
|
#command ⇒ Object
7
8
9
|
# File 'lib/dumper/database/mongodb.rb', line 7
def command
"cd #{tmpdir} && #{dump_tool_path} #{connection_options} #{additional_options} && tar -czf #{filename} ."
end
|
#config_for(rails_env = nil) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dumper/database/mongodb.rb', line 22
def config_for(rails_env=nil)
return unless defined?(Mongo::DB) &&
(mongo = find_instance_in_object_space(Mongo::DB))
{
:host => mongo.connection.host,
:port => mongo.connection.port,
:database => mongo.name,
:dump_tool => dump_tool_path
}.tap do |h|
if auth = mongo.connection.auths.first
h.update(:username => auth['username'], :password => auth['password'])
end
end
end
|
#connection_options ⇒ Object
11
12
13
14
15
16
|
# File 'lib/dumper/database/mongodb.rb', line 11
def connection_options
[ :database, :host, :port, :username, :password ].map do |option|
next if @stack.configs[:mongodb][option].blank?
"--#{option}='#{@stack.configs[:mongodb][option]}'".gsub('--database', '--db')
end.compact.join(' ')
end
|