Recover Deleted Records (Historical Candidates)

When data in a MongoDB collection is accidentally deleted, use PDU to scan retained historical sources and export candidate pre-delete data. The following sections describe configuration, scanning and export in detail.


I. Initialization

1.1 Preserve the Data Files and Historical Sources

Preserve copies of history store, pre-images and oplog that already exist at the incident. History-store values may have been reclaimed, and pre-images may have been disabled or expired. Old values that were not retained cannot be recreated.

1.2 Configure pdu.ini

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

1.3 Start PDU and Execute Initialization

./pdu

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

Review collection bindings, historical sources and unresolved dependencies in catalog records. Create a new task for old catalog records rather than automatically upgrading source identity.


II. Scan Historical Data

2.1 Navigate to the Target Collection

use appdb;
\dt;
\d orders;

Use the collection name resolved by the catalog. For database-wide scanning, specify the database with db database_name.

2.2 Execute the Scan Command

param resmode history;
param restype delete;
scan appdb.orders;

# Or scan the selected database:
scan db appdb;

2.3 Understanding the Scan Output

Review sources, candidate versions and unresolved reasons in native records. Collection history, history store and pre-images retain separate records; their candidate counts are not a unique business-record count.

ds catalog status;
ds batch status;
ds batch log;

III. Restore Data

Use restore to export offline candidates for the target collection. The command does not connect to a running MongoDB server or automatically update a target collection.

restore appdb.orders;

# Or export candidates for the selected database:
restore db appdb;

IV. Filter by Operation Range

When attributable pre-images and oplog remain available, limit the range by operation timestamp. operationfrom is inclusive and operationbefore is exclusive. Both use SECONDS:INCREMENT, not a business Date field or incident wall-clock time.

param operationfrom 1700000000:1;
param operationbefore 1700000010:1;
ds preimage scan appdb.orders delete;
ds preimage unload appdb.orders delete;
param operationfrom none;
param operationbefore none;

Output Files

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.

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.


Common Issues

  • Missing history store: retain the missing dependency; a current export is not accidental-operation recovery.
  • Missing MODIFY base or intermediate versions: retain unresolved reasons without generating guessed values.
  • Unclear pre-image attribution or transaction commit: retain old values and evidence without forcing classification.
MongoDB 文档