Data backup is one of the most highly required processes for any database management system as data can be lost or corrupted. To overcome these drawbacks, we need database backup. Database backup is a copy of a database that already exists. In MongoDB, the mongodump tool is used to take the data backup. And mongorestore tool is used to restore the backup data.
In MongoDB, the mongodump tool is used to take the data backup. It simply dumps all the data stored into a dump directory of MongoDB. Backed-up data is in BSON format, also known as BSON data dumps. By default, the backup is stored in mongodb’s bin\dump folder. To specify a different output directory, we can use the –out option. Mongodump is used in two ways, with or without argument.
Without any arguments, mongodump connects with MongoDB instance on the local system on port 27017 and creates a backup of every database and collection.
By specifying the database in the argument by which, we can limit the amount of data stored in the database dump
In MongoDB, the mongorestore utility is used to restore the backup data. It restores the binary backup created by the mongodump utility(i.e., BSON data dumps). It can restore either an entire database backup or a subset of the backup. It also restores the indexes created for any collection inside that database. By default, mongorestore looks for a database backup in mongodb’s bin\dump folder, the default folder for the mongodump command for dumping the backup.
You should follow some best practices when using the MongoDB backup and restore services for your MongoDB clusters.
|