How to backup a MongoDB database

17 de octubre, 2017 @ 11:57 — 0 comentariosDownload PDF

To backup a MongoDB database, mongodump tool should be used. This tool is already installed and available in our hosting services.

Backup

This command will store the content of the database in the output DIR directory, you can use the command as follows:

 mongodump -h HOST -u USER -p PASSWORD --authenticationDatabase DATABASE -d DATABASE -o DIR 

Restore

To restores  a MongoDB database, mongorestore tool should be used. This tool too is already installed and available in our hosting services. you can use the command as follows:

 mongorestore -h HOST -u USER -p PASSWORD --authenticationDatabase DATABASE -d DATABASE DIR 

This one does the oposite of mongodump. Reads the content in the DIR directory and restores it to the DATABASE.