MongoDB - SPLessons

MongoDB Backup

Chapter 22

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

MongoDB Backup

MongoDB Backup

shape Description

A MongoDB Backup means duplication of information from a particular database that can be utilized to remake that information. MongoDB Backup can be classified into 2 types, such as

Physical backup

Physical backups means backing up of the physical records utilized for accumulating and recuperating the database. For example archived redo logs, control documents and documents containing the data.

Logical backup

Logical backups consisting of coherent information. Such as storing procedures strategies and tables.

Mongodump

shape Description

For performing mongodb database back up, the command mongodump should be used. These mongodump command will dump each and every information within the directory of dump. There are numerous alternatives accessible for which the client can confine the measure of information or make reinforcement of the client’s isolated server.

shape Syntax

The syntax for dump command is as follows.
>mongodump

And there are many command that are accessible to perform the execution of mongodump command,Such as:

Syntax Explanation Example
Mongodump–collection–COLLECTION–db DB_NAME The following command will intend for reinforcement just only the determined set of indicated database. Mongodump–collection mycol–db test
Mongodump–host HOST_NAME–port PORT_NUMBER All the databases will be backedup by using the command of mongodb Mongodump–host site name–port 27107
Mongodump–dbpath DB_PATH–out BACKUP_DIRECTORY All the databases will be backedup by using the command of mongodb Mongodump–dbpath/data/db/–out/data/backup

shape Examples

By viewing the below example the concept of dump command can be easily understand.

c:Program Files\MongoDB\Server\3.2\bin>mongodump
connected to :127.0.0.1
Wen July 13 09:45:12.789 all dbs
Wen July 13 09:45:12.793 DATABASE:test to dump\test
Wen July 13 09:45:12.795          test.system.indexes to dump\test\system.indexes.bson
Wen July 13 09:45:12.798                 4 objects
Wen July 13 09:45:12.800          test.my to dump\test\my.bson
Wen July 13 09:45:12.803                 0 objects
Wen July 13 09:45:12.803          Metadata for test.my to dump\test\my.metadata.json
Wen July 13 09:45:12.807          test.cool1 to dump\test\cool1.bson
Wen July 13 09:45:12.810                 1 objects
Wen July 13 09:45:12.812          Metadata for test.cool1 to dump\test\cool1.metadata.json
Wen July 13 09:45:12.814          test.mycol to dump\test\mycol.bson
Wen July 13 09:45:12.817                 2 objects
Wen July 13 09:45:12.819          Metadata for test.mycol to dump\test\mycol.metadata.json

Here in the above example, the mongodump command will dump each and every information into the dump directory.

Restoring information

shape Description

For restoring information in MongoDB Backup the command backup technique mongostore is utilized. By using the command each and every information will be restored from the backup index.

shape Syntax

The syntax for restoring information the following command is used.
>mongostores

In the command prompt if we are performing this restore information all the records that has been removed from the directory will be restored back to the main mongodb server.

Summary

shape Key Points

  • MongoDB Backup – Is used to create the backup of MongoDB database.
  • MongoDB Creating Backup – Means duplicating the data from the particular database.
  • Mongodump – Dump each and every information into the directory of dump.
  • Restoring Information – All the data will be restored from the backup index.