How do you take a consistent backup of a MongoDB replica set?
Short answer
For small/medium data, run mongodump --oplog against a member, which captures the oplog during the dump so the backup is point-in-time consistent, and restore with mongorestore --oplogReplay. For large data, use filesystem/volume snapshots of a secondary or a managed backup (Atlas, Ops Manager, Percona Backup for MongoDB) which also supports PITR.
mongodump with oplog
mongodump --uri="mongodb://backup:***@mongo-1:27017/?replicaSet=rs0&readPreference=secondary" \
--oplog --gzip --archive=/backups/rs0_$(date +%F).gz
mongorestore --uri="mongodb://admin:***@new-host:27017" --oplogReplay --gzip --archive=/backups/rs0_2026-11-26.gz
--oplog only works for a whole-instance dump (not a single --db).
Snapshot approach
- Pick a secondary; ensure journaling is on (default).
- Take an EBS/disk snapshot (or
db.fsyncLock()→ snapshot →db.fsyncUnlock()if data and journal are on different volumes). - Restore by attaching the volume to a new instance.
Good practice
Back up from a secondary to avoid loading the primary, keep copies off-site and encrypted, and test restores regularly.
What to say in the interview
"mongodump with --oplog from a secondary gives a point-in-time consistent dump that mongorestore replays with --oplogReplay. At scale, volume snapshots or tools like Percona Backup for MongoDB or Atlas backups provide faster restores and PITR — and we test restores."