MongoDB / Advanced: distributed and recoverable operations / Lesson 16
Backup, recovery and restore evidence
Choose recoverable artifacts from loss and recovery-time requirements. Distinguish self-managed tools, consistent snapshots and Atlas backup capabilities without inventing universal guarantees.
On this page
Lesson goals
- Explain logical backup, consistency boundaries and restore requirements.
- Validate restored business data and independent recovery artifacts.
A backup method follows the recovery objective
Recovery point objective states acceptable data loss and recovery time objective states acceptable service restoration delay. A nightly export alone cannot promise five-minute recovery history. mongodump and mongorestore are database tools with their own supported server compatibility and restore semantics, not a universal snapshot of every live topology. Filesystem snapshots require a documented consistency procedure. Atlas backup and point-in-time capabilities depend on the deployment and service tier, so verify the actual policy instead of assuming every cluster has the same retention or restore feature.
Inventory more than document counts
A usable restore can require indexes, collection options, validators, users or role configuration, application secrets and compatible tooling according to the selected method and scope. The read-only examples inspect index and collection metadata only in the training namespace. They do not create a backup or prove that an artifact includes those definitions. Record encryption-key access and external dependencies separately, without storing secrets in course text or a public incident record. Keep tool and server versions with the protected recovery manifest.
db.getSiblingDB('quay_lab').bookings.getIndexes();
db.getSiblingDB('quay_lab').getCollectionInfos({ name: 'bookings' });
Metadata visibility requires suitable privileges. Actual definitions are environment-dependent and are not fabricated.
Concurrent writes require a supported consistency strategy
A collection-by-collection logical dump during active writes should not be assumed to represent one coherent instant across all business documents. Replica-set oplog capture and replay options have specific restrictions, while sharded backups need coordinated handling of distributed metadata and writes. Do not extrapolate a standalone recipe to a sharded cluster. Restore to an isolated destination and preserve the source. A malformed or untrusted backup can also carry executable restore behavior or unwanted definitions, so provenance and controlled restore privileges belong in the runbook.
Check a restored invariant at the correct grain
Assume restored training bookings store total and an array of line amounts, all numeric. The pipeline calculates a line total within each document and returns mismatches, rather than unwinding and accidentally multiplying parent totals. With a correctly restored fixture satisfying that explicit invariant, expected output is empty. A real system may add tax, discounts or rounding and must define its own accounting rule. An empty mismatch query is one piece of evidence, not proof that every collection, permission and historical recovery boundary is correct.
db.getSiblingDB('restored_quay_lab').bookings.aggregate([
{ $project: { total: 1, lineTotal: { $sum: '$lines.amount' } } },
{ $match: { $expr: { $ne: ['$total', '$lineTotal'] } } },
{ $sort: { _id: 1 } }
]);
Expected for numeric, internally consistent fixture documents: no mismatches. Missing or malformed amounts require separate type validation.
Prove independence and controlled service ownership
Keep protected artifacts outside the source failure domain and rehearse loss of the original host, credentials and ordinary administrative access. Verify known good records, excluded unwanted changes, index definitions and application behavior using the intended service role. Measure provisioning, restore, replay and validation within the recovery-time budget. Before cutover, fence old writers and define one authoritative destination. Replication can faithfully copy a bad delete, so it does not replace historical backup. No restore, snapshot, cloud operation or server administration is executed by this course.
Common errors and fixes
A dump restores documents but the service still fails
- Why it happens
- Required metadata, privileges, tooling or external configuration was omitted.
- How to fix it
- Compare the manifest and validate the intended application identity.
- Prevent it next time
- Include service behavior and metadata in restore rehearsals.
Backup success is assumed from job completion only
- Why it happens
- Artifact recoverability and consistency were never tested.
- How to fix it
- Restore a protected copy in isolation and verify business invariants.
- Prevent it next time
- Measure end-to-end recovery against RPO and RTO.
A replica set is treated as historical recovery
- Why it happens
- Current replicated copies were confused with retained earlier states.
- How to fix it
- Retain independent historical artifacts and a verified recovery boundary.
- Prevent it next time
- Test accidental deletion as well as node failure.
Check your understanding
1. A nightly dump is the only artifact, but the business accepts ten minutes of data loss. Is the objective demonstrated?
Show worked solution
No. Select and verify a supported continuous-history or more frequent consistent-backup strategy suitable for the actual topology, service tier and tooling. Prove retention completeness and rehearse the full restore within RTO. A vendor feature name or an artifact created yesterday does not establish that the last ten minutes of business history can be recovered.
2. Why must restored data be checked with the service role rather than only an administrator account?
Show worked solution
Administrative access can hide missing grants and allow operations that the real application cannot perform. Verify required reads, writes or transactions through an isolated representative application path with its intended identity, while checking denied excess capabilities. Structural document restoration and usable least-privilege service restoration are different acceptance conditions.
Key takeaways
- Recovery depends on consistency, topology, metadata and protected independent history.
- Restore rehearsals establish evidence that a completed backup job cannot provide alone.