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.



52
53
54
55
# File 'lib/backup/database/mongodb.rb', line 52

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



30
31
32
# File 'lib/backup/database/mongodb.rb', line 30

def additional_options
  @additional_options
end

#authdbObject

Credentials for the specified database



14
15
16
# File 'lib/backup/database/mongodb.rb', line 14

def authdb
  @authdb
end

#hostObject

Connectivity options



18
19
20
# File 'lib/backup/database/mongodb.rb', line 18

def host
  @host
end

#ipv6Object

IPv6 support (disabled by default)



22
23
24
# File 'lib/backup/database/mongodb.rb', line 22

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.



39
40
41
# File 'lib/backup/database/mongodb.rb', line 39

def lock
  @lock
end

#nameObject

Name of the database that needs to get dumped



10
11
12
# File 'lib/backup/database/mongodb.rb', line 10

def name
  @name
end

#only_collectionsObject

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



26
27
28
# File 'lib/backup/database/mongodb.rb', line 26

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.



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

def oplog
  @oplog
end

#passwordObject

Credentials for the specified database



14
15
16
# File 'lib/backup/database/mongodb.rb', line 14

def password
  @password
end

#portObject

Connectivity options



18
19
20
# File 'lib/backup/database/mongodb.rb', line 18

def port
  @port
end

#usernameObject

Credentials for the specified database



14
15
16
# File 'lib/backup/database/mongodb.rb', line 14

def username
  @username
end

Instance Method Details

#perform!Object



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

def perform!
  super

  lock_database if @lock
  dump!
  package!

ensure
  unlock_database if @lock
end