Class: MongodbClone::MongodbReplication
- Inherits:
-
Object
- Object
- MongodbClone::MongodbReplication
- Defined in:
- lib/mongodb_clone.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #dump(environment = 'production', session = 'default') ⇒ Object
-
#initialize ⇒ MongodbReplication
constructor
A new instance of MongodbReplication.
- #restore(environment = 'development', session = 'default') ⇒ Object
Constructor Details
#initialize ⇒ MongodbReplication
Returns a new instance of MongodbReplication.
9 10 11 |
# File 'lib/mongodb_clone.rb', line 9 def initialize @id = Time.now.utc.strftime('%Y%m%d%H%M%S') end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/mongodb_clone.rb', line 7 def id @id end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/mongodb_clone.rb', line 7 def path @path end |
Instance Method Details
#dump(environment = 'production', session = 'default') ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mongodb_clone.rb', line 13 def dump(environment = 'production', session = 'default') config = base_config[environment.to_s]['sessions'][session.to_s] params = { h: config['hosts'][0], d: config['database'], u: config['username'], p: config['password'], o: "/tmp/#{ config['database'] }/#{ @id }" } a = params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ') command = "mongodump #{ a }" execute(command) @path = "#{ params[:o] }/#{ params[:d] }" self end |
#restore(environment = 'development', session = 'default') ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mongodb_clone.rb', line 35 def restore(environment = 'development', session = 'default') config = base_config[environment.to_s]['sessions'][session.to_s] params = { h: config['hosts'][0], d: config['database'], u: config['username'], p: config['password'] } a = params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ') command = "mongorestore --drop #{ a } #{ @path }" execute(command) end |