Data Backup
In MongoDB, 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 Argument:
Without any arguments, mongodump connects with MongoDB instance on the local system on port 27017 and creates a backup of every database and every collection.
mongodump
With Argument:
By specifying the database in the argument by which we can limit the amount of data stored in the database dump
mongodump --db databaseName --collection collectionName
To specify a different output directory we can use the –out option:
mongodump –db databaseName –collection collectionName –out c:\backup
Example 1: Backing up all the databases
Here we have 10 databases which all get backed up in the folder backupDatabase.
Note– exit mongo shell by ctrl+c to use the mongodump command.
mongodump --out c:\backupDatabase
Example 2: Backing up the specified collection
Here, we are making a backup of the collection student which contains 6 documents and is inside the w3wiki database, the backup is made inside the GFGbackup Folder.
mongodump –db w3wiki –collection students –out c:\GFGbackup
MongoDB – Backup and Restoration
Data backup is one of the most highly required processes for any database management system as data can be lost or get corrupted to overcome these drawbacks we need database backup. Database backup is a copy of a database that already exists. In MongoDB, mongodump tool is used to take the data backup. And mongorestore tool is used to restore the backup data.
Contact Us