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

Instance Method Summary collapse

Methods included from Configuration::Helpers

included

Constructor Details

#initialize(model, &block) ⇒ MongoDB

Creates a new instance of the MongoDB database object



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

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

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

  instance_eval(&block) if block_given?

  @mongodump_utility  ||= utility(:mongodump)
  @mongo_utility      ||= utility(:mongo)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backup::Configuration::Helpers

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



45
46
47
# File 'lib/backup/database/mongodb.rb', line 45

def lock
  @lock
end

#mongo_utilityObject

Path to the mongo utility (optional)



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

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



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

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