Class: Backup::Database::MongoDB
- Defined in:
- lib/backup/database/mongodb.rb
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Builds a MongoDB compatible string for the additional options specified by the user.
-
#host ⇒ Object
Connectivity options.
-
#ipv6 ⇒ Object
Returns the mongodump syntax for enabling ipv6.
-
#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
-
#collections_to_dump ⇒ Object
Returns an array of collections to dump.
-
#connectivity_options ⇒ Object
Builds the MongoDB connectivity options syntax to connect the user to perform the database dumping process.
-
#credential_options ⇒ Object
Builds the MongoDB credentials syntax to authenticate the user to perform the database dumping process.
-
#database ⇒ Object
Returns the MongoDB database selector syntax.
-
#dump! ⇒ Object
Builds and runs the mongodump command.
-
#dump_directory ⇒ Object
Returns the MongoDB syntax for determining where to output all the database dumps, e.g.
-
#initialize(&block) ⇒ MongoDB
constructor
Creates a new instance of the MongoDB database object.
-
#mongodump ⇒ Object
Builds the full mongodump string based on all attributes.
-
#perform! ⇒ Object
Performs the mongodump command and outputs the data to the specified path based on the ‘trigger’.
-
#specific_collection_dump! ⇒ Object
For each collection in the @only_collections array, it’ll build the whole ‘mongodump’ command, append the ‘–collection’ option, and run the command built command.
Methods inherited from Base
Methods included from Configuration::Helpers
#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods
Methods included from CLI
Constructor Details
#initialize(&block) ⇒ MongoDB
Creates a new instance of the MongoDB database object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/backup/database/mongodb.rb', line 33 def initialize(&block) load_defaults! @only_collections ||= Array.new @additional_options ||= Array.new @ipv6 ||= false instance_eval(&block) prepare! end |
Instance Attribute Details
#additional_options ⇒ Object
Builds a MongoDB compatible string for the additional options specified by the user
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
Returns the mongodump syntax for enabling ipv6
21 22 23 |
# File 'lib/backup/database/mongodb.rb', line 21 def ipv6 @ipv6 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
#collections_to_dump ⇒ Object
Returns an array of collections to dump
73 74 75 |
# File 'lib/backup/database/mongodb.rb', line 73 def collections_to_dump @only_collections end |
#connectivity_options ⇒ Object
Builds the MongoDB connectivity options syntax to connect the user to perform the database dumping process
57 58 59 60 61 62 |
# File 'lib/backup/database/mongodb.rb', line 57 def %w[host port].map do |option| next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?) "--#{option}='#{send(option)}'" end.compact.join("\s") end |
#credential_options ⇒ Object
Builds the MongoDB credentials syntax to authenticate the user to perform the database dumping process
47 48 49 50 51 52 |
# File 'lib/backup/database/mongodb.rb', line 47 def %w[username password].map do |option| next if send(option).nil? or send(option).empty? "--#{option}='#{send(option)}'" end.compact.join("\s") end |
#database ⇒ Object
Returns the MongoDB database selector syntax
79 80 81 |
# File 'lib/backup/database/mongodb.rb', line 79 def database "--db='#{ name }'" end |
#dump! ⇒ Object
Builds and runs the mongodump command
121 122 123 |
# File 'lib/backup/database/mongodb.rb', line 121 def dump! run(mongodump) end |
#dump_directory ⇒ Object
Returns the MongoDB syntax for determining where to output all the database dumps, e.g. ~/Backup/.tmp/MongoDB/<databases here>/<database collections>
92 93 94 |
# File 'lib/backup/database/mongodb.rb', line 92 def dump_directory "--out='#{ dump_path }'" end |
#mongodump ⇒ Object
Builds the full mongodump string based on all attributes
98 99 100 101 |
# File 'lib/backup/database/mongodb.rb', line 98 def mongodump "#{ utility(:mongodump) } #{ database } #{ } " + "#{ } #{ ipv6 } #{ } #{ dump_directory }" end |
#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
109 110 111 112 113 114 115 116 117 |
# File 'lib/backup/database/mongodb.rb', line 109 def perform! log! if collections_to_dump.is_a?(Array) and not collections_to_dump.empty? specific_collection_dump! else dump! end end |
#specific_collection_dump! ⇒ Object
For each collection in the @only_collections array, it’ll build the whole ‘mongodump’ command, append the ‘–collection’ option, and run the command built command
129 130 131 132 133 |
# File 'lib/backup/database/mongodb.rb', line 129 def specific_collection_dump! collections_to_dump.each do |collection| run("#{mongodump} --collection='#{collection}'") end end |