Learn the procedure to Create Backup in MongoDB:
In this tutorial, we will learn how to Create a Backup in MongoDB.
In application development information, backup and restoring have a critical point of view for any developer. MongoDB provides two utilities “mongodump” to create a backup and “mongorestore” to restore the backup.
Both of these utilities work with BSON. It is mostly used for small level application deployment and recovery. There are many other methods as well which you can follow to create a proper backup.
In this tutorial, we will use a simple approach to create a backup for the whole managed instance. We will simply dump all the data into the dump folder and this is the simplest approach to create a proper backup.
Initially, we have to start the MongoDB server. In our case, it is running on IP:127.0.0.1 and Port:27017.
Figure 1: Results in MongoDB Shell
Now we have to open CMD with the privileges of the administrator. Then point the directory where the MongoDB Bin folder is located as you can see in the below image.
Figure 2: Results in CMD Shell
After this, we will execute the mongodump command to create a backup folder with the name of the dump within the Bin folder. By default, there is no dump folder available before the mongodump command execution. When we execute this command it will download all the information into the dump folder.
Each collection is separated as a folder. Now execute this command and it will generate the response which you can see in the below image.
Figure 3: Results in CMD Shell
After the execution, let's visit the dump folder within the Bin folder of Mong0DB. Here you can observe that each collection has a separate folder. Data is a dump in the form of JSON and BSON within the collection folder.
Figure 4: Results in MongoDB Dump Folder
Creating a backup of MongoDB is critical in development. Developers have to maintain a backup of collection based on how important the information is stored. Basically, a backup processes each month and for an enterprise application, it is recommended to process daily.
In this tutorial, we saw a simple solution to create a backup with a few commands. If you are a beginner, you can have this approach for backup of your collections. You just need to point the command prompt to the Bin folder and execute the above command, and it will dump all the data automatically.
Check out our upcoming tutorial to know more Deployment in MongoDB.