Documents Changed Incorrectly, but Pre-images Survive?

Recover Pre-Image Old Documents

Scenario Description

Pre-images were enabled, and local.system.preimages retains old documents after the incident together with matching oplog. Typed _id, UUID and operation times can establish attribution before exporting pre-change documents in the confirmed range.

Possible Causes

  • Documents were updated or deleted by mistake.
  • Pre-images have not expired or been purged.
  • Old documents must be attributed to specific operations.

Challenges

Conventional recovery often requires complete files, a running instance or a usable backup. In these situations, choose a method based on the evidence that survives.

Common Errors and Symptoms

  • - Pre-image data exists, but business collection relationships need confirmation.
  • - Matching oplog and commit-closure evidence are required.
  • - One document may have several pre-operation images.

Why Traditional Methods Fail

  • - Business _id alone cannot establish pre-image operation identity.
  • - Missing oplog can leave operation attribution unresolved.
  • - An unclosed transaction is not a confirmed committed state.

PDU Solution

PDU reads pre-images and matching oplog separately, using UUIDs, typed identifiers and operation ranges to identify the associated operations. Select a confirmed logical-time interval, then export old documents and the original state records.

Recovery Principle

  1. Preserve Pre-images and Oplog
  2. Bind UUID and Operation
  3. Select Logical-time Range
  4. Export Pre-change Documents

PDU Core Capabilities

  • Dedicated preimage scan and export.
  • Select collections or databases.
  • Attribute typed _id and UUID values.
  • Retain matching oplog and commit evidence.
  • Use inclusive lower and exclusive upper operation bounds.
  • Record complete candidates and partial units separately.

Recovery Steps

  1. 1

    Initialization

    In directory mode, the catalog links pre-images to target collections by UUID. If oplog is missing, save the complete old documents and keep operation types unknown. Do not classify every old value as a deletion or update.

  2. 2

    Scan Old Documents

    Use the corresponding command example below, replacing paths, objects and identity parameters with evidence from this run.

  3. 3

    Set an Operation Range (Optional)

    Replace example values with actual source timestamps. Ranges use source logical operation/commit timestamps, with an inclusive start and exclusive end in SECONDS:INCREMENT format. They are not business Date fields or incident wall-clock time.

    Important: Ranges Apply Only to the Pre-Image Path

    Ordinary scan/restore and other paths reject active operation ranges. Reset both operationfrom and operationbefore to none before switching paths rather than relying on silent omission.

  4. 4

    Export Attributable Old Values

    Ordinary operations and members of complete, unique SOURCE transaction commit chains can enter matching filters. Retain old documents and reasons for open, aborted, incomplete or ambiguous transactions without forcing a committed business-operation classification.

  5. 5

    Handle Missing Pages and Active Units

    For damaged pages, PDU keeps readable branches and records PREIMAGE_SOURCE_PARTIAL. Complete, unaffected source chains can still be filtered; incomplete members remain unknown. Run the following command only after deciding to abandon an unfinished output unit.

Quick Command Examples

Preserve frozen sources and launch PDU outside them. Write configuration snippets to pdu.ini and execute PDU commands after startup. Replace example paths, versions, times and task identities with actual evidence.

# Initialization

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

# Initialization

param sourceversion 8.0.0;
param sourcekind copy;
param sourcefrozen true;
param resmode history;

# Initialization

b;
ds catalog status;

# Scan Old Documents

ds preimage scan appdb.orders;
ds preimage scan db appdb update;

# Set an Operation Range (Optional)

param operationfrom 1700000000:1;
param operationbefore 1700000010:1;
ds preimage scan appdb.orders update;

# Export Attributable Old Values

ds preimage unload appdb.orders update;
param operationfrom none;
param operationbefore none;

# Handle Missing Pages and Active Units

ds preimage discard-active appdb.orders update;

Export Results

Old-value Candidates

Keep complete values, physical versions and unresolved candidates separate without overwriting current collections.

Historical Evidence

Retain sources, collection relationships, transaction or operation times and candidate reasons.

Native Status

Record completed output, unfinished units, missing chains and checkpoints separately.

After export, record PDU’s native success and failure counts and original errors, retaining checkpoints. Resume uses native records and file metadata without rereading exported data or automatic trial import.

Prerequisites

  • This documentation applies to Linux and source versions MongoDB 6.0.0, 7.0.0 and 8.0.0. Freeze source copies and launch PDU from a directory outside the sources. State and output use the launch directory without separate path settings. Confirm other versions and special layouts separately.
  • Existing pre-images, matching UUID and required oplog are needed. Enabling pre-images afterward does not restore old values already lost.
  • Prepare a matching program, license and sufficient space. Keep original evidence read-only and place the PDU launch directory outside the sources.

Important Notes

  • Disabled, expired or overwritten pre-images cannot be recreated.
  • Operation ranges come from actual oplog times rather than business date fields.
  • Replace example timestamps and source IDs with evidence from the current run.
MongoDB 场景案例