Class: Monsoon::Backup
- Inherits:
-
Object
- Object
- Monsoon::Backup
- Defined in:
- lib/monsoon/backup.rb
Instance Method Summary collapse
-
#config ⇒ Object
Creates the config hash for the connection string.
-
#database ⇒ Object
Helper method for database name.
-
#initialize(uri) ⇒ Backup
constructor
A new instance of Backup.
-
#mongo_dump_command ⇒ Object
Helper to form the mongodump command.
-
#run ⇒ Object
Run the Monsoon Backup process.
Constructor Details
#initialize(uri) ⇒ Backup
Returns a new instance of Backup.
6 7 8 |
# File 'lib/monsoon/backup.rb', line 6 def initialize(uri) @uri = uri end |
Instance Method Details
#config ⇒ Object
Creates the config hash for the connection string
Examples
Monsoon::Backup("mongodb://test.mongohq.com:10036/app_development").config
# => {"host" => "test.mongohq.com",
"post" => 10036,
"database" => "app_development",
"username" => "testuser",
"password" => "pass1"}
Returns an instance of the Monsoon::Backup class
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/monsoon/backup.rb', line 35 def config return {} unless @uri uri = URI.parse(@uri) raise "must be a mongo DB" unless uri.scheme == 'mongodb' { "host" => uri.host, "port" => uri.port, "database" => uri.path.gsub(/^\//, ''), "username" => uri.user, "password" => uri.password } end |
#database ⇒ Object
57 58 59 |
# File 'lib/monsoon/backup.rb', line 57 def database config["database"] end |
#mongo_dump_command ⇒ Object
69 70 71 72 73 74 |
# File 'lib/monsoon/backup.rb', line 69 def mongo_dump_command cmd = "" cmd = "mongodump -h #{config['host']}:#{config['port']} -d #{config['database']} -o . " cmd += "--username #{config['username']} --password #{config['password']}" unless config["username"].nil? and config["password"].nil? cmd end |
#run ⇒ Object
18 19 20 21 |
# File 'lib/monsoon/backup.rb', line 18 def run Kernel.system "#{mongo_dump_command}" self end |