Class: Backup::Database::MongoDB

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

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Attributes inherited from Base

#database_id, #dump_path, #model

Instance Method Summary collapse

Methods included from Config::Helpers

included

Constructor Details

#initialize(model, database_id = nil, &block) ⇒ MongoDB

Returns a new instance of MongoDB.



50
51
52
53
# File 'lib/backup/database/mongodb.rb', line 50

def initialize(model, database_id = nil, &block)
  super
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

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

Instance Attribute Details

#additional_optionsObject

Additional “mongodump” options



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

def additional_options
  @additional_options
end

#authdbObject

Credentials for the specified database



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

def authdb
  @authdb
end

#hostObject

Connectivity options



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

def host
  @host
end

#ipv6Object

IPv6 support (disabled by default)



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

def ipv6
  @ipv6
end

#lockObject

Forces mongod to flush all pending write operations to the disk and locks the entire mongod instance to prevent additional writes until the dump is complete.

Note that if Profiling is enabled, this will disable it and will not re-enable it after the dump is complete.



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

def lock
  @lock
end

#nameObject

Name of the database that needs to get dumped



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

def name
  @name
end

#only_collectionsObject

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



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

def only_collections
  @only_collections
end

#oplogObject

Creates a dump of the database that includes an oplog, to create a point-in-time snapshot of the state of a mongod instance.

If this option is used, you would not use the ‘lock` option.

This will only work against nodes that maintain a oplog. This includes all members of a replica set, as well as master nodes in master/slave replication deployments.



48
49
50
# File 'lib/backup/database/mongodb.rb', line 48

def oplog
  @oplog
end

#passwordObject

Credentials for the specified database



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

def password
  @password
end

#portObject

Connectivity options



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

def port
  @port
end

#usernameObject

Credentials for the specified database



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

def username
  @username
end

Instance Method Details

#perform!Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/backup/database/mongodb.rb', line 55

def perform!
  super

  lock_database if @lock
  dump!
  package!

ensure
  unlock_database if @lock
end