Class: Monsoon::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/monsoon/backup.rb

Instance Method Summary collapse

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

#configObject

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

#databaseObject

Helper method for database name.

Examples

Monsoon::Backup("mongodb://test.mongohq.com:10036/app_development").database
# => "app_development"

Returns a String of the database name.



57
58
59
# File 'lib/monsoon/backup.rb', line 57

def database
  config["database"]
end

#mongo_dump_commandObject

Helper to form the mongodump command.

Examples

Monsoon::Backup("mongodb://test.mongohq.com:10036/app_development").mongo_dump_command
# => "mongodump -h test.mongohq.com:10036 -d app_development"

Returns the command as a String.



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

#runObject

Run the Monsoon Backup process.

Examples

Monsoon::Backup("mongodb://@test.mongohq.com:10036/app_development").run
# => #<Monsoon::Backup>

Returns an instance of the Monsoon::Backup class



18
19
20
21
# File 'lib/monsoon/backup.rb', line 18

def run
  Kernel.system "#{mongo_dump_command}"
  self
end