Backup and restore capabilities are critical for any database system. Amazon DocumentDB (with MongoDB compatibility) provides robust backup solutions to protect your data. In this guide, I'll walk you through all the key concepts and practical CLI commands you need to effectively manage DocumentDB backups.
Understanding DocumentDB Backup Options
DocumentDB offers two types of backups:
- Automated backups: Enabled by default with a retention period of 1-35 days
- Manual snapshots: User-initiated backups that persist until explicitly deleted
Key benefits of DocumentDB backups:
- Point-in-time recovery (for automated backups)
- Cluster restoration to any second within retention period
- No performance impact during backup operations
- Storage usage is optimized by only backing up changed data
Backup Storage Usage
DocumentDB backups are incremental - only changed data since the last backup is stored. Storage usage depends on:
- Data volume
- Change rate
- Backup retention period
You're charged for total backup storage used beyond the size of your provisioned storage (which includes 100% of your data size for free).
Creating Manual Snapshots
Manual snapshots are perfect for long-term retention beyond 35 days or before major changes.
aws docdb create-db-cluster-snapshot \
--db-cluster-snapshot-identifier my-snapshot \
--db-cluster-identifier my-cluster
Check status with:
aws docdb describe-db-cluster-snapshots \
--db-cluster-snapshot-identifier my-snapshot
Copying Snapshots Across Regions
For disaster recovery, copy snapshots to another region:
aws docdb copy-db-cluster-snapshot \
--source-db-cluster-snapshot-identifier arn:aws:docdb:us-east-1:123456789012:snapshot:my-snapshot \
--target-db-cluster-snapshot-identifier my-snapshot-copy \
--kms-key-id my-kms-key \
--region us-west-2
Sharing Snapshots Across Accounts
Share snapshots with other AWS accounts:
aws docdb modify-db-cluster-snapshot-attribute \
--db-cluster-snapshot-identifier my-snapshot \
--attribute-name restore \
--values-to-add ["123456789012"]
Restoring from Snapshots
Restore a cluster from either automated or manual snapshots:
aws docdb restore-db-cluster-from-snapshot \
--db-cluster-identifier my-restored-cluster \
--snapshot-identifier my-snapshot \
--engine docdb \
--vpc-security-group-ids sg-12345678 \
--db-subnet-group-name my-subnet-group
Then create instances for the restored cluster:
aws docdb create-db-instance \
--db-cluster-identifier my-restored-cluster \
--db-instance-identifier my-restored-instance \
--db-instance-class db.r5.large \
--engine docdb
Deleting Snapshots
When you no longer need a manual snapshot:
aws docdb delete-db-cluster-snapshot \
--db-cluster-snapshot-identifier my-snapshot
Import/Export Data Using mongodump/mongorestore
For granular data operations:
Export data:
mongodump --uri="mongodb://username:password@my-cluster.node.us-east-1.docdb.amazonaws.com:27017" --ssl --sslCAFile rds-combined-ca-bundle.pem --out /tmp/mydbdump
Import data:
mongorestore --uri="mongodb://username:password@my-cluster.node.us-east-1.docdb.amazonaws.com:27017" --ssl --sslCAFile rds-combined-ca-bundle.pem /tmp/mydbdump
Key Considerations
- Performance Impact: Backup operations don't affect cluster performance
- Retention: Automated backups are deleted when cluster is deleted (unless converted to manual snapshot)
- Encryption: All snapshots inherit the encryption of the source cluster
- Restore Time: Depends on data size (typically several minutes to hours)
Best Practices
- Regularly test restore procedures
- Use manual snapshots before major changes
- Consider cross-region copies for critical data
- Monitor backup storage usage
- Automate snapshot management where possible
By mastering these backup and restore techniques, you can ensure your DocumentDB data remains protected while meeting your organization's recovery objectives. The AWS CLI commands provided give you full control over the backup lifecycle, from creation to restoration and deletion.
Remember to adjust parameters like region, instance identifiers, and security settings to match your specific environment. Happy backing up!
Top comments (0)