In this bankruptcy, we can see the way to create a backup in MongoDB.
Dump MongoDB Data
To create backup of database in MongoDB, you must use mongodump command. This command will dump the entire facts of your server into the dump listing. There are many options to be had by which you could restriction the quantity of statistics or create backup of your faraway server.
Syntax
The simple syntax of mongodump command is as follows −
>mongodump
Example
Start your mongod server. Assuming that your mongod server is running at the localhost and port 27017, open a command spark off and visit the bin directory of your mongodb example and sort the command mongodump
Consider the mycol series has the following statistics.
>mongodump
The command will connect to the server jogging at 127.Zero.Zero.1 and port 27017 and lower back all information of the server to directory /bin/sell off/. Following is the output of the command −
Following is a listing of to be had options that may be used with the mongodump command.
Syntax | Description | Example |
---|---|---|
mongodump --host HOST_NAME --port PORT_NUMBER | This commmand will backup all databases of specified mongod instance. | mongodump --host tutorialspoint.com --port 27017 |
mongodump --dbpath DB_PATH --out BACKUP_DIRECTORY | This command will backup only specified database at specified path. | mongodump --dbpath /data/db/ --out /data/backup/ |
mongodump --collection COLLECTION --db DB_NAME | This command will backup only specified collection of specified database. | mongodump --collection mycol --db test |
Restore statistics
To restore backup records MongoDB's mongorestore command is used. This command restores all the facts from the backup listing.
Syntax
The fundamental syntax of mongorestore command is −
>mongorestore
Following is the output of the command −