The simplest way to backup and restore MongoDB data is to use bson dumps. This is achieved by using the mongodump
and mongorestore
utilities and works best for small databases.
Backup
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 mongodump
parameters.
Restore
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.
Finally, a new theme and comments box now working…
How about MongoDB running in Kubernetes?