MongoDB: How to restore and backup MongoDB database.

Backup and recovery is two most valuable parts in database in case of system failure or unexpected system crash or database replacement.

In MongoDB, data can be import and exported using commands.

Lets move on MongoDB command:

Before starting import and export you need to start mongo using terminal and open a new terminal and navigate to that folder where you want to backup your database.

Open terminal and navigate to that directory where your MongoDB is installed and after that, type below commands.

Backup for one database in MongoDB, execute the below commands.

mongodump --host localhost --port 27017 --db db_name

Where db_name is your database name.

Restore for one database, execute below commands.

mongorestore --host localhost --port 27017 --db new_db_name dump/db_name

Where db_name is your old database name and new_db_name is your new database name.

Backup for total database, execute below command.

mongodump --host localhost --port 27017

Restore for total database, execute below command

mongorestore --host localhost --port 27017  dump
Advertisements

One thought on “MongoDB: How to restore and backup MongoDB database.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s