1. Home
  2. MongoDB Tutorial
  3. MongoDB – Backup and Restore

MongoDB – Backup and Restore

This Tutorial explains how to Backup a MongoDB database and restore data from a backup. MongoDB provides utility to Backup and Restore Database.

Create Directory:

First create a directory to save mongodb backup.

$ mkdir -p /opt/mongodb-backups

MongoDB Backup:

Use below command to backup MongoDB database.

Syntax:

mongodump --host <hostname> OR <IP> --port 27017 -u <mongouser> --authenticationDatabase <authdb> --db <dbname> --out /opt/mongodb-backups/

Example:

Here We are taking backup of database name “Employee”,

$ mongodump --host 192.168.100.10 --port 27017 -u fossadmin -p --authenticationDatabase admin --db Employee --out /opt/mongodb-backups/

Restore MongoDB backup:

To Restore MongoDB Backup.

Syntax:

$ mongorestore --host <hostname> OR <IP>  --port <portnumber> -u $mongo_user -p $mongo_pass -d dbname -c $collection $file

Example:

Restoring MongoDB backup of database name “Employee” to another database.

$ mongorestore --host 192.168.100.12 --port 27017 -u $fossadmin -p [email protected] -d Employee -c $collection $file

 

 

 

Was this article helpful to you? Yes No

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.