MongoDB Tutorial 0/120 lessons ~6 min read Lesson 85

    Backup Strategies

    Backup is the last line of defense against bad code, ransomware and human error.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Backup is the last line of defense against bad code, ransomware and human error. A replica set protects against hardware failure; it does not protect against db.dropDatabase(). Backups are independent, point-in-time copies stored away from the cluster.

    MongoDB Atlas offers continuous cloud backups with point-in-time restore down to the second. Self-hosted teams use mongodump, file-system snapshots, or Ops Manager. Whichever you choose, the rule is the same: untested backups don't exist.

    Learning objective: Apply Backup Strategies correctly in a TechLearningPRO MongoDB workload — with clear data-model choices, safe writes, and failure modes you can explain in review.

    Treat every example as production-shaped MongoDB: explicit projections, indexes that match the access path, and Atlas-safe defaults. Prefer mongosh / Node driver shapes used in SaaS backends.

    Purpose of this lesson

    Apply Backup Strategies correctly in a TechLearningPRO MongoDB workload — with clear data-model choices, safe writes, and failure modes you can explain in review.

    Understanding the topic

    The four backup strategies — pick at least one:

    • Atlas Continuous Backup — oplog-tailing, PIT restore to any second in the last 7–30 days. Set-and-forget for cloud teams.
    • Atlas Cloud Snapshots — daily/weekly EBS-style snapshots, fastest restore for whole-cluster recovery.
    • mongodump / mongorestore — logical BSON export. Portable, slow on large clusters, excellent for collection-level restores.
    • Filesystem snapshots (LVM, EBS) — fast, requires fsyncLock or journaling. Used by ops teams self-hosting.
    • Ops Manager / Cloud Manager — enterprise on-prem; oplog tailing + scheduled snapshots + PIT.

    Step-by-step explanation

    1. State when Backup Strategies is the right MongoDB tool versus an alternative.
    2. Map the diagram boxes to driver, mongod, WiredTiger, and your collection.
    3. Run the smallest correct mongosh / driver example against a TechLearningPRO learners collection.
    4. Name two failure modes (missing index, bad shard key, unbounded scan) and how you detect them.

    Informative example

    Daily backup with mongodump, gzipped and shipped to S3:

    bash
    #!/usr/bin/env bash
    set -euo pipefail
    TS=$(date -u +%Y%m%dT%H%M%SZ)
    mongodump --uri="$MONGO_URI" --archive=/tmp/dump-$TS.gz --gzip --readPreference=secondaryPreferred
    aws s3 cp /tmp/dump-$TS.gz s3://acme-mongo-backups/$TS.gz --storage-class GLACIER_IR
    # 30-day retention, automated lifecycle policy on the bucket
    rm /tmp/dump-$TS.gz

    Real-world use

    Every regulated industry (banking, healthcare, gov) requires daily off-cluster backups with documented RPO/RTO. Most SaaS teams run Atlas continuous + a weekly mongodump to a cold S3 bucket for the "two backup providers" rule.

    Security implications

    MongoDB is a trust boundary. Drivers must not interpolate untrusted input into query operators.

    • Never build queries by concatenating user strings into operator objects.
    • Use least-privilege Atlas database users; apps should not have root.
    • Enable TLS and avoid exposing mongod on public networks.

    Best practices

    • Define and publish your RPO (recoverable point objective) and RTO (recoverable time objective).
    • Run a restore drill monthly — restore to a sandbox and verify checksums.
    • Use secondary reads for mongodump so the primary keeps serving traffic.
    • Encrypt backups at rest and require MFA to download them.

    Common mistakes

    • "We have replication, we're fine" — replication is not backup.
    • Storing backups in the same cloud account as production — one compromised IAM key kills both.
    • Untested backups — the day you need them is the worst day to find out they're corrupt.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionWhat is Backup Strategies and when do you use it?+

    Answer

    Atlas continuous backup is the default for cloud workloads.
    2IntermediateQuestionHow would you verify Backup Strategies is working in production?+

    Answer

    mongodump + S3 cold storage is the universal fallback.
    3AdvancedQuestionWhat breaks if you misuse Backup Strategies?+

    Answer

    RPO + RTO + monthly restore drills = a real backup strategy.

    Hands-on exercise

    Hands-on drill:

    • Implement the smallest correct example for Backup Strategies on a learners/orders-like collection.
    • Capture explain('executionStats') and confirm an index was used when expected.

    Summary

    Backup Strategies is a production MongoDB skill: model for your read path, prove it with explain(), and ship with indexes and least-privilege roles.

    Ready to mark this lesson complete?Track your journey across the entire course.