Class: Backup::Database::MongoDB
- Defined in:
- lib/backup/database/mongodb.rb
Constant Summary
Constants included from CLI::Helpers
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Additional “mongodump” options.
-
#host ⇒ Object
Connectivity options.
-
#ipv6 ⇒ Object
IPv6 support (disabled by default).
-
#lock ⇒ Object
‘lock’ dump meaning wrapping mongodump with fsync & lock.
-
#mongo_utility ⇒ Object
Path to the mongo utility (optional).
-
#mongodump_utility ⇒ Object
Path to the mongodump utility (optional).
-
#name ⇒ Object
Name of the database that needs to get dumped.
-
#only_collections ⇒ Object
Collections to dump, collections that aren’t specified won’t get dumped.
-
#password ⇒ Object
Credentials for the specified database.
-
#port ⇒ Object
Connectivity options.
-
#username ⇒ Object
Credentials for the specified database.
Instance Method Summary collapse
-
#initialize(model, &block) ⇒ MongoDB
constructor
Creates a new instance of the MongoDB database object.
-
#perform! ⇒ Object
Performs the mongodump command and outputs the data to the specified path based on the ‘trigger’.
Methods included from Configuration::Helpers
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_options ⇒ Object
Additional “mongodump” options
29 30 31 |
# File 'lib/backup/database/mongodb.rb', line 29 def @additional_options end |
#host ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/mongodb.rb', line 17 def host @host end |
#ipv6 ⇒ Object
IPv6 support (disabled by default)
21 22 23 |
# File 'lib/backup/database/mongodb.rb', line 21 def ipv6 @ipv6 end |
#lock ⇒ Object
‘lock’ dump meaning wrapping mongodump with fsync & lock
45 46 47 |
# File 'lib/backup/database/mongodb.rb', line 45 def lock @lock end |
#mongo_utility ⇒ Object
Path to the mongo utility (optional)
41 42 43 |
# File 'lib/backup/database/mongodb.rb', line 41 def mongo_utility @mongo_utility end |
#mongodump_utility ⇒ Object
Path to the mongodump utility (optional)
33 34 35 |
# File 'lib/backup/database/mongodb.rb', line 33 def mongodump_utility @mongodump_utility end |
#name ⇒ Object
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_collections ⇒ Object
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 |
#password ⇒ Object
Credentials for the specified database
13 14 15 |
# File 'lib/backup/database/mongodb.rb', line 13 def password @password end |
#port ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/mongodb.rb', line 17 def port @port end |
#username ⇒ Object
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 |