MOngoDB database file loss, database startup error resolution process

[Introduction to MongoDB database environment]

Recently, the data recovery center recovered a MongoDB data from a local customs. First, the database environment is introduced:
the database where the data is lost is located on a virtual machine, and the operating system of the virtual machine is WindowsServer 2012. Because the business needs to migrate the files in the database, the administrator copies the database files to other partitions when the MongoDB service is turned on, and the data in the original database partition is formatted. However, the migrated data cannot be used. After the administrator copies the data back to the original partition, the MongoDB service is still unusable, and the error "Windows cannot start the MongoDB service (on the local computer) error 1067: The process terminated unexpectedly."
MOngoDB database file loss, database startup error resolution process

[Preliminary inspection of MongoDB database failure]

The engineer conducted a preliminary understanding based on the customer’s description. Normally, if the MongoDB service has not been shut down, copying the database file back will cause errors in the copying of the two files mongod.lock and WiredTiger.lock. After this occurs, you can Find these two files in the copied files and delete them. After restarting MongoDB, the database will automatically regenerate these two files, and the database can be started normally.
Subsequently, the engineer inspected the files migrated by the customer according to this prediction, but unexpectedly, the mdbcatalog.wt file was missing in the migrated database files.
The mdbcatalog.wt file is a file specially used to store all collection metadata in MongoDB. The relevant information that must be read when the database is started is stored in the modified file. Therefore, the cause of the customer database startup error should be the loss of the mdbcatalog.wt file. The database cannot obtain the WT table name of the collection bet, the creation options of the collection, the index information of the collection and other metadata, which caused the database startup error. .

[Database data recovery]

The data recovery engineer first scanned the underlying data of the database partition, but did not scan the information about the mdbcatalog.wt file. After adjusting the scanning method for many attempts, it still could not find the relevant information. It was determined that the changed file was overwritten and the reply could not be passed. The mdbcatalog.wt file repairs the database.
Therefore, the data recovery engineer adjusted the data recovery strategy. Since the customer's database is a database system based on the WiredTiger storage engine, the executable wt tool was compiled in the Windows environment.
MOngoDB database file loss, database startup error resolution process
With the help of the compiled wt tool, all data in the database collection file is cleaned and written back, and the data read result is written into the file. Create a brand new MongoDB database, create a collection of corresponding data volume, write files into the collection one by one, query the data set and rebuild the index information.
By querying the records in the collection, determining the record type, rebuilding the collection index, the collection is restored, and the data can be viewed normally:

MOngoDB database file loss, database startup error resolution process
MOngoDB database file loss, database startup error resolution process

[Check the data and confirm that the data is restored successfully]

After assisting the customer to rebuild the index of all the collections, the customer queries the database as a whole, and the data is correct. The data recovery was a complete success.
*

Guess you like

Origin blog.51cto.com/sun510/2533079