Working with Backup Strategies
1. Using mongodump for Backup
mongodump --uri="mongodb://user:pwd@host/db" --out=/backup
2. Using mongorestore for Restore
mongorestore --uri=... /backup
3. Backing Up Specific Database
| Flag | Detail |
|---|---|
| --db | Single DB |
| --nsInclude | Glob patterns (multi-DB) |
4. Backing Up Specific Collection
| Flag | Detail |
|---|---|
| --collection | One collection |
| --query / --queryFile | Filter docs |
5. Using --oplog for Point-in-Time Recovery
| Flag | Detail |
|---|---|
| --oplog | Captures oplog during dump for consistency |
| Requires | Replica set |
6. Restoring with --oplogReplay
| Flag | Detail |
|---|---|
| --oplogReplay | Replay oplog after restore |
| --oplogLimit ts | Restore up to specific timestamp |
7. Creating Filesystem Snapshots
| Aspect | Detail |
|---|---|
| Tool | LVM, EBS, ZFS snapshot |
| Consistency | Use db.fsyncLock() or journal-consistent snapshots |
8. Using Cloud Backup Solutions
| Service | Detail |
|---|---|
| Atlas Cloud Backups | Continuous + snapshot PIT recovery |
| Ops Manager | Self-hosted equivalent |
9. Backing Up Replica Sets
| Practice | Detail |
|---|---|
| Hidden secondary | Dedicated backup source |
| --oplog | Consistent point-in-time |
10. Backing Up Sharded Clusters
| Step | Detail |
|---|---|
| Stop balancer | Avoid in-flight migrations |
| Backup config + each shard | Consistent timestamps |
| Easier path | Atlas / Ops Manager backups |
11. Implementing Backup Schedules
| Tier | Frequency |
|---|---|
| Full | Daily / weekly |
| Incremental (oplog) | Continuous |
| Retention | Per RPO requirement |
12. Testing Backup Restoration
| Practice | Detail |
|---|---|
| Restore drills | Quarterly minimum |
| Verify counts | Compare doc counts / checksums |
| App-level test | Smoke-test critical queries |