Create Backup in MongoDB

To create a database Backup in MongoDB, you should use the mongodump command. This command will dump all Server data into dump directory. There are many options available from which you can limit the amount of data or backup created by Remote Server.

The mongodump command in MongoDB

To create a database Backup in MongoDB, you should use the mongodump command. This command will dump all Server data into dump directory. There are many options available from which you can limit the amount of data or backup created by Remote Server.

Syntax

The basic syntax of the mongodump command in MongoDB is:

 > mongodump 

For example

Start Mongod Server. Suppose your server is running on locallhost and port 27017. Now, open a command prompt and go to the bin directory of Mongodb Instance, then compose the mongodump command.

You monitor the Collection named mycol with the following data:

 > mongodump 

This command will connect to the running Server at 127.0.0.1 and port 27017 and backup the entire data of the Server to the / bin / dump directory . The result of this command is as follows:

Create Backup in MongoDB Picture 1

Here are some available options that can be used with the mongodump command.

Syntax Description mongodump --host HOST_NAME --port PORT_NUMBER This command will back up all databases of the mongodump --host definedspoint.com --port instance 27017 mongodump --dbpath DB_PATH - out BACKUP_DIRECTORY This command only backs up the database specified in the given path. mongodump --dbpath / data / db / --out / data / backup / mongodump --collection COLLECTION --db DB_NAME This command only backs up the specified Collection of the database with the --collection mycol --db kiểm TRA

Data recovery in MongoDB

To restore backed up data in MongoDB, use the mongorestore command. This command restores all data from the backup folder.

Syntax

The basic syntax of the mongorestore command is:

 > mongorestore 

The result of the order is:

Create Backup in MongoDB Picture 2

According to Tutorialspoint

Previous post: Shard in MongoDB

Next article: MongoDB Deployment

4 ★ | 2 Vote | 👨 617 Views
« PREV POST
NEXT POST »