Instance Damaged, but Only One Database Needs Recovery?

Recover Single Database

Scenario Description

A MongoDB instance contains several business databases, but one needs priority recovery. The complete frozen directory is readable, while the instance cannot be reached. Confirm databases and collections using matching catalogs, then export only the target database.

Possible Causes

  • An instance-level failure affects multiple business databases.
  • Recovery must proceed in business-priority batches.
  • Different databases contain collections with the same name.

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

  • - The target database is inaccessible, but a directory copy survives.
  • - Only appdb is needed, with other databases deferred.
  • - Some collections have missing files or batch failures.

Why Traditional Methods Fail

  • - Collection filenames alone cannot group files by business database.
  • - Removing catalogs or shared dependencies loses attribution evidence.
  • - Success for some collections does not establish a complete target database.

PDU Solution

PDU initializes a directory copy that is no longer being written and lists its databases and collections through the catalog. Select a database to export one collection or the whole database. Batch state records the actual results for each collection.

Recovery Principle

  1. Read Catalog Relationships
  2. Select Business Database
  3. Confirm Collection Scope
  4. Export Target Documents

PDU Core Capabilities

  • List databases confirmed by catalogs.
  • Select a database and inspect collections.
  • Retain namespace/UUID.
  • Export collection and database scopes separately.
  • Inspect batch status and native logs.
  • Keep scopes explicit across multiple databases.

Recovery Steps

  1. 1

    Initialize the Database Directory

    Important Notice

    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.

  2. 2

    View Database List

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

  3. 3

    View Collection List and Information

    Confirm target collections from namespace and UUID in the catalog. Do not assign unbound sources directly to that database.

  4. 4

    Export Data

    Collection and database exports keep separate batch records. Repeating a command uses PDU's completion records to continue without parsing completed output units again.

  5. 5

    Output File Structure

    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.

  6. 6

    Recover Multiple Databases

    Use use to select each target database and execute unload db separately. Retain separate batch records, output and native completion states for each database.

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.

# Initialize the Database Directory

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

# Initialize the Database Directory

param sourceversion 8.0.0;
param sourcekind copy;
param sourcefrozen true;
b;
\l;
use appdb;
\dt;

# View Database List

\l;

# View Collection List and Information

use appdb;
\dt;
\d orders;

# Export Data

unload coll orders;
unload db appdb;

# Export Data

ds batch status;
ds batch log;

# Recover Multiple Databases

unload db appdb;
use auditdb;
unload db auditdb;

Export Results

Recovered Documents

BSON or the selected data format at paths reported by the program.

Sources and Attribution

Retain namespace/UUID, source positions and candidate states; unresolved attribution stays unknown.

Tasks and Dependencies

The launch directory retains native tasks, checkpoints and original reasons for missing pages or overflow.

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

  • Preserve the complete dbPath; collection and history files may share the directory.
  • Collections, catalog and historical sources for a database may share dbPath. Preserve them together and select recovery objects by the logical database name.
  • Prepare a matching program, license and sufficient space. Keep original evidence read-only and place the PDU launch directory outside the sources.

Important Notes

  • Retain required catalogs and dependencies rather than trimming the physical directory by business database name.
  • Directory export neither rolls back to before the incident nor imports into the business instance automatically.
MongoDB 场景案例