Class: Backup::Database::MongoDB

Inherits:
Base
  • Object
show all
Defined in:
lib/backup/database/mongodb.rb

Constant Summary

Constants included from CLI::Helpers

CLI::Helpers::UTILITY

Instance Attribute Summary collapse

Attributes inherited from Base

#utility_path

Instance Method Summary collapse

Methods included from Configuration::Helpers

#clear_defaults!, #load_defaults!

Methods included from CLI::Helpers

#command_name, #raise_if_command_failed!, #run, #utility

Constructor Details

#initialize(model, &block) ⇒ MongoDB

Creates a new instance of the MongoDB database object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/backup/database/mongodb.rb', line 45

def initialize(model, &block)
  super(model)

  @only_collections   ||= Array.new
  @additional_options ||= Array.new
  @ipv6               ||= false
  @lock               ||= false

  instance_eval(&block) if block_given?

  if @utility_path
    Logger.warn "[DEPRECATED] " +
      "Database::MongoDB#utility_path has been deprecated.\n" +
      "  Use Database::MongoDB#mongodump_utility instead."
    @mongodump_utility ||= @utility_path
  end
  @mongodump_utility  ||= utility(:mongodump)
  @mongo_utility      ||= utility(:mongo)
end

Instance Attribute Details

#additional_optionsObject

Additional “mongodump” options



29
30
31
# File 'lib/backup/database/mongodb.rb', line 29

def additional_options
  @additional_options
end

#hostObject

Connectivity options



17
18
19
# File 'lib/backup/database/mongodb.rb', line 17

def host
  @host
end

#ipv6Object

IPv6 support (disabled by default)



21
22
23
# File 'lib/backup/database/mongodb.rb', line 21

def ipv6
  @ipv6
end

#lockObject

‘lock’ dump meaning wrapping mongodump with fsync & lock



41
42
43
# File 'lib/backup/database/mongodb.rb', line 41

def lock
  @lock
end

#mongo_utilityObject

Path to the mongo utility (optional)



37
38
39
# File 'lib/backup/database/mongodb.rb', line 37

def mongo_utility
  @mongo_utility
end

#mongodump_utilityObject

Path to the mongodump utility (optional)



33
34
35
# File 'lib/backup/database/mongodb.rb', line 33

def mongodump_utility
  @mongodump_utility
end

#nameObject

Name of the database that needs to get dumped



9
10
11
# File 'lib/backup/database/mongodb.rb', line 9

def name
  @name
end

#only_collectionsObject

Collections to dump, collections that aren’t specified won’t get dumped



25
26
27
# File 'lib/backup/database/mongodb.rb', line 25

def only_collections
  @only_collections
end

#passwordObject

Credentials for the specified database



13
14
15
# File 'lib/backup/database/mongodb.rb', line 13

def password
  @password
end

#portObject

Connectivity options



17
18
19
# File 'lib/backup/database/mongodb.rb', line 17

def port
  @port
end

#usernameObject

Credentials for the specified database



13
14
15
# File 'lib/backup/database/mongodb.rb', line 13

def username
  @username
end

Instance Method Details

#perform!Object

Performs the mongodump command and outputs the data to the specified path based on the ‘trigger’. If the user hasn’t specified any specific collections to dump, it’ll dump everything. If the user has specified collections to dump, it’ll loop through the array of collections and invoke the ‘mongodump’ command once per collection



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/backup/database/mongodb.rb', line 71

def perform!
  super

  lock_database if @lock
  @only_collections.empty? ? dump! : specific_collection_dump!

rescue => err
  raise Errors::Database::MongoDBError.wrap(err, 'Database Dump Failed!')
ensure
  unlock_database if @lock
  package! unless err
end