8.3 Backup, Restore & Performance Telemetry

Key Takeaways

  • mongodump and mongorestore are binary backup and restoration utilities that export and ingest raw BSON (.bson) and index metadata (.metadata.json), preserving 100% type fidelity and index definitions.
  • Point-in-time consistent backups of live replica sets are achieved using 'mongodump --oplog' and restored via 'mongorestore --oplogReplay' to replay operations captured during the backup window.
  • Key backup flags include --archive (single consolidated stream), --gzip (compression), --nsInclude/--nsExclude (namespace filtering), and --drop (drops target collection before restore).
  • mongostat monitors real-time, second-by-second cluster operational telemetry, including CRUD rates, WiredTiger dirty/used cache percentages, active connections, and queued operations.
  • mongotop profiles read and write time utilization per collection, instantly identifying database I/O hotspots.
Last updated: September 2026

8.3 Backup, Restore & Performance Telemetry

Maintaining data durability, executing rapid disaster recovery, and diagnosing real-time performance bottlenecks are fundamental responsibilities in MongoDB database administration and application development. MongoDB provides a comprehensive suite of binary backup tools and command-line telemetry utilities:

  1. mongodump & mongorestore: High-performance binary BSON backup and restoration utilities that preserve exact data types, index definitions, and collection metadata.
  2. mongostat: Real-time server telemetry monitor that reports live CRUD operation throughput, active connections, lock queues, and WiredTiger cache pressure.
  3. mongotop: Real-time profiling monitor that tracks CPU and lock time utilization on a per-collection basis.

1. Binary Backups: mongodump & mongorestore Fundamentals

Unlike mongoexport (which generates lossy, human-readable JSON or CSV text files), mongodump creates a binary BSON dump of the database. It connects directly to a running mongod or mongos instance, reads the raw documents, and outputs binary .bson files alongside .metadata.json files.

Structure of a mongodump Output Directory

By default, mongodump creates a directory named dump/ containing subdirectories for each database:

dump/
├── ecommerce/
│   ├── customers.bson          <- Raw binary BSON document records
│   ├── customers.metadata.json <- Index definitions, collection options, collations
│   ├── orders.bson
│   └── orders.metadata.json
└── admin/
    ├── system.users.bson
    └── system.users.metadata.json

Advantages of Binary BSON Dumps

  • 100% BSON Type Fidelity: Types like Decimal128, 64-bit Long, ISODate, ObjectId, and Binary are preserved bit-for-bit without string conversion or lossy float casting.
  • Index Definitions Restored Automatically: The .metadata.json files contain the full index specifications (compound indexes, partial indexes, TTL settings, unique constraints, and custom collation rules). mongorestore automatically rebuilds these indexes.
  • Storage Efficiency: Binary BSON combined with in-line compression (--gzip) is significantly smaller and faster to process than text-based JSON exports.

2. Advanced mongodump Capabilities & Point-in-Time Consistency

The Critical --oplog Option for Live Consistent Snapshots

In an active production database, client applications continuously execute write operations while mongodump is running. If a dump takes 30 minutes to complete, documents dumped at minute 1 may reference documents modified or deleted by minute 29, resulting in an inconsistent backup snapshot.

To achieve Point-in-Time Consistency, mongodump provides the --oplog flag:

# Capture a point-in-time consistent binary backup of an active replica set
mongodump --uri="mongodb://primary.example.com:27017" \
  --oplog \
  --archive=./prod_backup_$(date +%Y%m%d).archive.gz \
  --gzip

How --oplog Works Internally:

  1. When mongodump starts, it records the current timestamp on the primary's Oplog (local.oplog.rs).
  2. It dumps the collection documents while simultaneously tailing and capturing all write operations recorded in the oplog during the dump window.
  3. It writes these operations into an oplog.bson file in the root of the dump output.
  4. When mongorestore is executed with --oplogReplay, it restores the collections and then applies the captured oplog entries up to the completion point, bringing the entire dataset into a mathematically consistent, point-in-time state.

[!CAUTION] --oplog Requirements: The --oplog option only works against replica set nodes (or master-slave instances) and only when dumping the entire cluster/server (you cannot use --oplog when specifying an individual collection via --collection).

Essential mongodump Flags

FlagPurpose & Description
--archive=<filePath>Consolidates the entire backup into a single archive file instead of a folder hierarchy. If specified without a path (--archive), streams binary data directly to stdout.
--gzipCompresses BSON files or the archive stream using GZIP on the fly, dramatically reducing disk usage.
--nsInclude="<db>.<coll>"Granular namespace inclusion filter supporting wildcards (e.g., --nsInclude="sales.*" or --nsInclude="*.orders").
--nsExclude="<db>.<coll>"Granular namespace exclusion filter (e.g., --nsExclude="analytics.audit_logs").
--oplogCaptures the oplog during the dump window to produce a point-in-time consistent snapshot.

3. Restoration Strategies with mongorestore

mongorestore reads binary BSON archives or directories produced by mongodump and writes the documents, collections, and index specifications back into a target MongoDB cluster.

Essential mongorestore Flags

  • --drop: Drops each collection from the target database before restoring it from the dump. This prevents duplicate key conflicts against preexisting documents.
  • --oplogReplay: Replays the oplog.bson captured during a mongodump --oplog backup to guarantee point-in-time consistency.
  • --nsInclude / --nsExclude: Selects specific namespaces to restore from an archive.
  • --nsFrom and --nsTo: Remaps namespaces dynamically during restoration (e.g., restoring data from production to a staging database).
  • --noIndexRestore: Restores collection documents without building secondary indexes. Useful for staging environments where developers want to inspect raw data immediately or build indexes in the background later.
  • --numParallelCollections <N> / -j <N>: Sets the number of collections to restore concurrently (defaults to 4).

Practical mongorestore Commands

# 1. Restore from a compressed single archive file with drop and oplog replay
mongorestore --uri="mongodb://localhost:27017" \
  --archive=./prod_backup_20260902.archive.gz \
  --gzip \
  --drop \
  --oplogReplay

# 2. Namespace Remapping: Restore 'production' database dump into 'staging'
mongorestore --uri="mongodb://staging.example.com:27017" \
  --archive=./prod_backup.archive.gz \
  --gzip \
  --nsFrom="production.*" \
  --nsTo="staging.*"

# 3. Restore a specific collection from a directory dump
mongorestore --uri="mongodb://localhost:27017" \
  --db=ecommerce \
  --collection=customers \
  --drop \
  ./dump/ecommerce/customers.bson

4. Real-Time Operational Telemetry: mongostat

mongostat is a live diagnostic tool that provides a high-level, second-by-second overview of the status of a running mongod or mongos instance. It is analogous to the Unix vmstat or iostat utility.

Running mongostat

# Poll the database every 1 second (default)
mongostat --uri="mongodb://localhost:27017"

# Poll every 5 seconds, displaying 10 total iterations
mongostat --uri="mongodb://localhost:27017" 5 10

Interpreting mongostat Output Columns

insert query update delete getmore command dirty  used flushes vsize   res qrw  arw net_in net_out conn                time
    *0  12500     *0     *0       0   150|0  2.1% 78.4%       0 16.4G 12.1G 0|15  1|4   4.2m   18.6m  450 2026-09-02T10:15:01Z
Column GroupMetric HeaderMeaning & Diagnostic Significance
CRUD Ratesinsert, query, update, deleteNumber of respective operations executed per second. Asterisks (e.g., *0) indicate secondary replica node operations.
Cursor BatchesgetmoreNumber of getmore requests per second (fetching subsequent batches from open query cursors). High getmore relative to query indicates queries returning massive result sets.
Command RatecommandNumber of database commands executed per second (e.g. aggregate, findAndModify, count). Format `local
WiredTiger CachedirtyPercentage of the WiredTiger cache containing modified (dirty) bytes waiting to be flushed to disk. Critical: If dirty exceeds 20%, WiredTiger throttles incoming writes.
WiredTiger CacheusedPercentage of configured WiredTiger cache currently occupied by data. If used exceeds 80%, background eviction threads aggressively page out clean data.
CheckpointsflushesNumber of WiredTiger checkpoint flushes to disk during the polling interval. Typically 0 between 60-second checkpoint intervals.
Process Memoryvsize / resVirtual memory (vsize) and Resident physical memory (res) allocated to the mongod process.
Lock Queues`qrqw`
Active Clients`araw`
Network I/Onet_in / net_outNetwork traffic entering and leaving the instance (in bytes, KB, or MB).
ConnectionsconnTotal number of open incoming client connection sockets.

Diagnostic Scenarios with mongostat

  1. Unindexed Query Storm: query is high, res is saturated, used is near 100%, and qr spikes as CPU and memory churn searching unindexed collections.
  2. Storage I/O Bottleneck: dirty exceeds 20%, qw (queued writers) rises steadily, and net_in drops because the disk cannot flush modified pages fast enough to accept new writes.
  3. Connection Leak: conn continuously climbs until reaching maxConns, rejecting new client connections.

5. Collection-Level Profiling: mongotop

While mongostat monitors server-level operation counts and memory pressure, mongotop tracks the amount of time a mongod instance spends performing read and write operations on a per-collection basis.

Running mongotop

# Poll collection time utilization every 3 seconds
mongotop --uri="mongodb://localhost:27017" 3

Interpreting mongotop Output

2026-09-02T10:15:30Z
                      ns    total     read    write
        ecommerce.orders   1482ms    210ms   1272ms
     ecommerce.inventory    340ms    315ms     25ms
     ecommerce.customers     85ms     85ms      0ms
          admin.system.roles      0ms      0ms      0ms
  • ns: Target collection namespace (<database>.<collection>).
  • total: Total active time spent by mongod servicing operations on this collection during the polling interval.
  • read: Time spent servicing read operations (queries, aggregations, scans).
  • write: Time spent servicing write operations (inserts, updates, deletes).

Diagnostic Value of mongotop

  • Pinpointing Hotspots: Instantly answers: "Which specific collection is consuming 90% of our database I/O?"
  • Read vs. Write Characterization: Reveals whether a busy collection is read-dominated (ecommerce.inventory spending 315ms reading) or write-dominated (ecommerce.orders spending 1272ms writing).

6. Diagnostic Tool Comparison Matrix

Diagnostic ToolScope of InspectionPrimary Metrics TrackedWhen to Use
mongostatEntire mongod/mongos Server InstanceGlobal ops/sec, CRUD rates, WiredTiger dirty/used cache %, `qrqwlock queues,conn`
mongotopPer-Collection NamespaceElapsed CPU/lock time (ms) spent in read, write, and total per collectionIdentifying which specific collection is causing database I/O hotspots
db.currentOp()Individual In-Flight Operations / Threadsopid, secs_running, planSummary (COLLSCAN), query filter, client IPLocating and killing specific slow or blocked queries in real time
db.stats()Database Storage ExtentsdataSize, storageSize, indexSize, freeStorageSize, document countEvaluating database capacity, compression ratio, and storage growth
Loading diagram...
Backup & Telemetry Architecture: mongodump Oplog Snapshots and Real-Time Monitoring
Test Your Knowledge

An administrator must take a full binary backup of an active, high-traffic production replica set while client applications continue to insert and update records. Which mongodump and mongorestore workflow ensures the restored database reflects a point-in-time consistent state?

A
B
C
D
Test Your Knowledge

While monitoring a cluster during peak traffic, an administrator observes in mongostat that the 'dirty' column is at 24% and the 'qw' column is rapidly increasing. What does this indicate about cluster health?

A
B
C
D
Test Your Knowledge

A development team reports that database read latency has spiked significantly. The administrator needs to identify which specific collection is consuming the largest amount of time servicing read operations across the entire database. Which tool should be used?

A
B
C
D
Test Your Knowledge

An administrator needs to restore a production database dump from 'prod_backup.archive.gz' into a development database named 'dev_testing', ensuring that any preexisting collections in 'dev_testing' are dropped first. Which command executes this correctly?

A
B
C
D