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.
Attributes inherited from Base
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
#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 ||= 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_options ⇒ Object
Additional “mongodump” options
29 30 31 |
# File 'lib/backup/database/mongodb.rb', line 29 def 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
41 42 43 |
# File 'lib/backup/database/mongodb.rb', line 41 def lock @lock end |
#mongo_utility ⇒ Object
Path to the mongo utility (optional)
37 38 39 |
# File 'lib/backup/database/mongodb.rb', line 37 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
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 |