How to create backup in MongoDB

Use the mongodump command for creating binary backups for your MongoDB instances.

Suppose you can access your MongoDB instance using this connection string:

mongodb://mongodb0.example.com:27017

And, you have the mongodump utility tool installed and accessible from your Terminal. (If it’s not, visit the MongoDB Database Tools Installation Guidehttps://www.mongodb.com/docs/database-tools/installation/installation/ before continuing with the steps below.)

Lastly, determine your backup destination folder. An example is, /backups/20210404/.

The command to kick off the final backup process would look like:

mongodump --uri="mongodb://mongodb0.example.com:27017" --out /backups/20210404/ -v

Here, I added the -v flag (short for --verbose mode) to display more reporting on the backup progress.

It should take some time to run. Once done, the dumped database will appear as bsonhttps://www.mongodb.com/docs/manual/reference/glossary/ files. You can then copy these files to another secured location or import them into another MongoDB instance.

You can use additional options, such as --gzip to compress the output and --archive to output the database dump to an archive file.

See the mongodump pagehttps://www.mongodb.com/docs/database-tools/mongodump/ for a full list of available backup optionshttps://www.mongodb.com/docs/database-tools/mongodump/.

Free Resources