How to recover Customer Data from Crashed MongoDB

Back

How to recover Customer Data from Crashed MongoDB

Lee Robinson

Ajith

- September 25, 2023

5 min read

ipaas-poster

MongoDB is one of the most widely used NoSQL databases. However, like any other software, it is not free from faults and can sometimes experience issues such as crashes and despite your best efforts, you will be unable to restart it. In such situations, it can be frustrating to lose all your data especially when your customer's data is at stake.

In one of the most recent incidents, our customer database crashed unexpectedly, and regardless of the efforts of the customer team, they were unable to restart the MongoDB instance. Restarting the database was not feasible because it was running an outdated version of MongoDB (V3.6).

However, there are steps you can take to recover data from crashed MongoDB. In this blog, we’ll go over these steps in detail.

This blog post focuses on the final approach we used to restore our database, which entailed getting data from the WiredTiger.wt file after exhausting all other possibilities.

Step 1: Installing the Latest MongoDB

  • We deployed the latest MongoDB server version in the local
  • Current db collection files are stored in: /var/lib/MongoDB
  • Server Crashed DB collection files exist in: /var/lib/MongoDB-old

Step 2: Creating a new database

  • Next, we created a new database called "recovery" using the following command:
use recovery
  • We then created a collection within this database and inserted a sample document to ensure that it was working correctly.
db.collection.insert({success: true})

Step 3: Finding the location

  • After ensuring that the new database and collection were working correctly, we used the "stats" command to find the location of the collection file on the disk:
db.collection.stats()
  • Search for the "uri" object in the output.
"uri" : "statistics:table:collection-0--403572953901086002"
  • Check the disk location in /var/lib/mongodb/collection-0--403572953901086002.wt
ipaas-poster

Step 4: Recovering the Data

  • Once we had located the collection file, we exited the MongoDB shell and stopped the database service.
sudo systemctl stop mongod
  • Next, we copied the old collection file from the crashed database and overwrote it with the new collection file:
sudo cp mongodb-old/collection-37-5631193714274098836.wt mongodb/collection-0--403572953901086002.wt
  • We then repaired the database using the following command:
sudo mongod --dbpath /var/lib/mongodb --repair
  • We also changed the ownership of the database files using the following command:
sudo chown -R mongodb:mongodb /var/lib/mongodb
  • Finally, we started the MongoDB service
sudo systemctl start mongod
  • We verified that the data was restored by checking the count of documents in the collection.
db.collection.count()
  • Rename Collection
db.collection.renameCollection("users")
  • We then repeated these steps for each collection in the database. Overall, these steps allowed us to recover the data from our crashed MongoDB instance and restore it to a new instance running the latest version of MongoDB. When MongoDB crashes, it can be frustrating and can result in loss of data. However, with the correct steps, you can recover your data. Remember to identify the cause of the crash, start MongoDB in recovery mode, check the logs, restart MongoDB, and recover data from backups if necessary. By following these steps, you can save your data and keep your project up and running.

  • Moreover, this way of getting back the data from crashed Database is done based on our SaaSly subject matter experts idea and soultoion for the problem that we face. We made our customer really satisfied and happy by giving back the values of their business data. Our experts form the agile ecovery team had done a fantastic job for the customer to save millions of dollars and Temporary data maintenance to run the business optimistically with theminimum downtime. If you this is the better way to use for your customers pls adopthios approach and for more insight Talk to our experts. Also, If you have more ideas nad suggestion connect with we shall explore and learn together .

Reach out to Saasly for a treasure trove of invaluable tips, tricks, and expert guidance on seamless development integrations.

Happy Developement and enjoy Reading our upcoming resources!

Stay tuned. For more integration details. Please visit Saasly App sources:https://saasly.in/apps

Know more?

Saasly offers a straightforward and accessible iPaaS Solution; simply get in touch with us. We are a trusted technology and solution partner for Zendesk, Microsoft, Shopify, Zoho, and Freshworks, focusing on platform integration services and app development. Our expertise shines in delivering iPaaS integration and implementation solutions on a global scale, particularly for seamlessly integrating Custom and Commercial Marketplace applications with SaaS products. Our objective is to optimize and automate your organization's business operations by harnessing the capabilities of iPaaS Solutions, providing more than just a service – a highly productive solution.