MongoDB Create Backup - MongoDB

How to create backup in Mongodb?

In this chapter, we will explain you how to create a backup in MongoDB.

Dump MongoDB Data

For creating a backup for database in MongoDB, use mongodump command. This command dumps the entire data of your server into the dump directory. There are many options which can be used to limit the amount of data or create backup of your remote server.

Syntax

Basic syntax of mongodump command is as follows

Example

Start mongod server. Suppose that your mongod server is running on the localhost and port 27017, open a command prompt and go to the bin directory of your mongodb instance and type the command mongodump

Consider the mycol collection has below data.

This command will connect to the server running at 127.0.0.1 and port 27017 and back all data of the server to directory /bin/dump/. Below is the output of the command

mongodump

Below is a list of available options which can be used with the mongodump command.

Syntax

Description

Example

mongodump --host HOST_NAME --port PORT_NUMBER

This command backs up all databases of specified mongod instance.

mongodump --host wisdomjobs.com --port 27017

mongodump --dbpath DB_PATH --out BACKUP_DIRECTORY

This command backs up only specified database at specified path.

mongodump --dbpath /data/db/ --out /data/backup/

mongodump --collection COLLECTION --db DB_NAME

This command backs up only specified collection of specified database.

mongodump --collection mycol --db test

Restore data

For restoring backup data MongoDB's, mongorestore command can be used. This command will restore all the data from the backup directory.

Syntax

Basic syntax of mongorestore command is

Below is the output of the command

mongorestore

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MongoDB Topics