How to backup a MongoDB database

17 de octubre, 2017 @ 11:57 — 0 comentarios

Backup

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

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

This command will store the content of the database in the output DIR directory

 

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.