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.


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


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

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

Restore MongoDB backup:

To Restore MongoDB Backup.


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


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

$ mongorestore --host --port 27017 -u $fossadmin -p $fosstechnix@123 -d Employee -c $collection $file




Leave a Comment

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