Recover from Corrupted Instance

When a MongoDB instance cannot open but the data directory is still available, PDU can directly read those files to export data without starting the database service.

I. Initialization

Set MONGODBDATA in pdu.ini to the frozen database directory. State and output use the directory where PDU is launched.

MONGODBDATA=/recovery-input/mongodb/source/dbpath

Enter the pdu directory and execute b; to complete initialization. PDU reads WiredTiger metadata and the MongoDB catalog to establish database and collection relationships.

./pdu

param sourceversion 8.0.0;
param sourcekind copy;
param sourcefrozen true;
b;
ds catalog status;

II. Enter the Specified Database and View Collection Information

2.1 View Current Databases

Use \l; to view selectable databases. Database names come from the matching catalog rather than collection filenames.

\l;

2.2 Enter Database and View Collection Information

Use use database_name; to select and enter the corresponding database. Use \dt; to view collections and \d collection_name; to view collection information.

use appdb;
\dt;
\d orders;

III. Export Data Under a Specified Database

Use unload coll collection_name; to export one collection, or unload db database_name; to export the specified database. current reads the selected checkpoint in the frozen copy without replaying the journal.

unload coll orders;

# Or export the database:
unload db appdb;

3.1 How to Use Exported Data

3.1.1 Components of Exported Data

Collection data is exported as BSON files or Canonical Extended JSON line files. Recovery commands generate offline candidate data without writing to the target database. Native records retain sources, success, failure, unresolved dependencies, original errors and checkpoints.

3.1.2 Paths of Exported Data

Exported files and task state are saved in the current working directory where PDU was started. Use the paths reported by PDU. Existing export results are not overwritten.

After export, record the native success and failure counts, unresolved dependencies and original errors reported by PDU, and retain the checkpoint. Resume uses native records and file metadata such as existence and size without rereading exported data.

3.1.3 Usage of Exported Data

Use the corresponding MongoDB import tool to import BSON or Extended JSON into a user-designated isolated collection. Handle indexes, validators and business relationships separately from original metadata. This procedure does not run an automatic trial import.

MongoDB 文档