Class: MongoDbUtils::CLI

Inherits:
Thor
  • Object
show all
Includes:
MongoDbUtils
Defined in:
lib/mongo-db-utils/cli.rb

Constant Summary

Constants included from MongoDbUtils

READY_FOR_USE, VERSION

Instance Method Summary collapse

Instance Method Details

#backup(mongo_uri, replica_set_name = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/mongo-db-utils/cli.rb', line 27

def backup(mongo_uri, replica_set_name = nil)
  config = get_config
  db = get_db(mongo_uri, replica_set_name)
  raise "can't parse uri" if db.nil?
  Cmd.backup(db, config.backup_folder)
end

#backup_s3(mongo_uri, bucket_name, access_key_id, secret_access_key, replica_set_name = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/mongo-db-utils/cli.rb', line 35

def backup_s3(mongo_uri, bucket_name, access_key_id, secret_access_key, replica_set_name = nil)
  config = get_config
  backup_folder = config.backup_folder
  db = get_db(mongo_uri, replica_set_name)
  raise "can't parse uri" if db.nil?
  Cmd.backup_s3(backup_folder, db, bucket_name, access_key_id, secret_access_key)
end

#console(path = ConfigLoader::CONFIG_LOCATION) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/mongo-db-utils/cli.rb', line 15

def console(path = ConfigLoader::CONFIG_LOCATION)

  if File.extname(path) != ".yml"
    puts "Error: You must use a yaml file as your config file location"
  else
    config = get_config(path)
    console = Console.new(config, Cmd)
    console.run
  end
end

#restore_from_s3(mongo_uri, bucket_name, access_key_id, secret_access_key, source_db, replica_set_name = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/mongo-db-utils/cli.rb', line 44

def restore_from_s3(mongo_uri, bucket_name, access_key_id, secret_access_key, source_db, replica_set_name = nil)
  config = get_config
  db = get_db(mongo_uri, replica_set_name)
  raise "can't parse uri" if db.nil?
  Dir.mktmpdir do |tmp_dir|
    backup = Cmd.download_backup_from_s3(tmp_dir, 'latest', bucket_name, access_key_id, secret_access_key)
    Cmd.restore_from_backup(tmp_dir, db, backup, source_db)
  end
end