The simplest way to backup and restore MongoDB data is to use bson dumps. This is achieved by using the
mongorestore utilities and works best for small databases.
Create a directory first where you wanted to store all your MongoDB backups then run the following command (assuming you have authentication set).
mongodump --host 127.0.0.1 --authenticationDatabase admin --forceTableScan -u username -p password-here
The command above should create a
dump directory where all your Mongo database files are stored. Check the documentation for the
To restore, use the
mongorestore utility. Run the following command (assuming you have authentication set).
mongorestore --host 127.0.0.1 --db dbname --username username --password password-here --authenticationDatabase admin dump/dbname
That’s it! For more advanced backup/restore strategy, you can explore incremental backups, volume based backups or even third party services that provides MongoDB backups.