MongoDB backup/restore
Want to know how the backup of mongo database can be taken. Read below…
Four tools are described here.
1) mongoexport
mongoexport can be used to take the backup of a mongo database. It takes the backup to a CSV, TSV or JSON files. The syntax is as follows.
-c is the collection name
-o is the file name to which the backup is to be taken
2) mongoimport
mongoimport can be used to import a backup to a database. You can import from the backup file as follows.
-c is the collection name
–file is the backup file
3) mongodump
For those who need a complete backup of the database, you can use mongodump command to do so. Unlike mongoexport, the backup will be done into a folder and not file.
-o is the folder to which data is to be backed up
Once completed, the backup will be present in /backuptest/db_test/
4) mongorestore
To restore an entire database, you can use the mongorestore command. Let’s restore the backup that we took in the previous step.
and the folder /backuptest/db_test/ is where the backup of db_test exists.
Try it and see, it works ![]()
Leave a Reply