Backup MongoDB – mongodump

Backup MongoDB – To backup data in MongoDB, MongoDB provides mongodump utility to backup data at different levels. Using mongodump, you may backup only a particular collection of a database, or single database, or all databases of a specified MongoDB instance.

Using mongodump utility

mongodump is an utility that could be run from a Terminal.

Following are the usages of mongodump utility :

  • To create backup for a collection in database, use mongodump with options : Collection Name and Database Name as shown below :
  • To create backup for a database, use mongodump with options : Database Path and Output Directory for Backup, as shown below :
  • To create backup all the databases linked to a specific MongoDB instance, use mongodump with options : Host Name and Port Number at which MongoDB instance is running, as shown below :
  • Running mongodump utility without any options creates backup for all databases linked to the MongoDB running at localhost (127.0.0.1) and port 27017 :

Note : When no –out option is specified, a directory named dump is created at the location from which mongodump utility is run.

Examples for MongoDB Backup

Make sure MongoDB Instance is running. If not, start one as shown below :

Backup MongoDB

Open a Terminal and run mongodump utility with no arguments

 

Backup MongoDB Collection

In this example, we shall backup “webpages” collection of “tutorialkart” db.

 

Backup MongoDB Database

In this example, we shall backup “tutorialkart” db.

 

Backup MongoDB Databases linked to a specific MongoDB instance

In this example, we shall backup all databases linked to the MongoDB instance running at 127.0.0.1:27017

 

Backup to a particular directory

–out option could be used to create backup at a particular directory

 

Conclusion :

In this MongoDB Tutorial, we have learnt to Backup MongoDB Databases and the control provided by mongodump utility for various levels in backup : Collection , Single Database, All Databases linked to a MongoDB Instance.