Most people find out how good their MongoDB backups are on the worst day of the year. This guide covers the setup that avoids that on AWS: automated daily backups to S3, a restore you've actually tried, and an honest look at what daily backups don't cover. Still deciding whether to self-host at all? We priced MongoDB Atlas against self-hosting on AWS tier by tier.
In short
Why MongoDB backups on AWS can't be optional
The failure that hurts isn't usually the server dying. AWS replaces hardware quietly. It's a bad migration script, a deleteMany with the wrong filter, or a compromised password. Replication copies those mistakes to every node within seconds, which is why a replica set is not a backup. Only a copy kept somewhere else, from before the mistake, gets the data back.
Regulation points the same way. GDPR and most security frameworks expect you to be able to restore personal data after an incident, and to prove you've tested it.
How the Meetrix MongoDB AMI backs up to S3
- Daily, automatic. The server writes a backup to S3 every day without anyone remembering to.
- Your bucket. You give an existing S3 bucket name when you launch the stack, so backups stay in your account, in a region you choose.
- Off the instance. If the EC2 instance or its volume is lost, the backups aren't.
- Standard tools. Nothing proprietary to restore from. The MongoDB Database Tools (
mongodump,mongorestore) work against it.
Video guide
Setting up MongoDB with automated S3 backup
You'll need an AWS account, basic familiarity with EC2 and CloudFormation, and an S3 bucket created in advance.
- Open the MongoDB AMI on AWS Marketplace, click "Continue to Subscribe" and accept the terms.
- Click "Continue to Configuration", pick your region, then "Continue to Launch" and choose "Launch CloudFormation".
- Fill in the stack: a stack name, DeploymentName, InstanceType (t3.small is the recommended start), your key pair, MongodbDatabase, MongodbUser, a strong MongodbPassword, and the S3Bucket name for backups.
- For SSHLocation and DatabaseSSHLocation, enter your own IP or your VPC range (for example
203.0.113.10/32), not0.0.0.0/0. Leaving port 27017 open to the internet is how MongoDB databases end up ransomed. - Acknowledge that CloudFormation may create IAM resources, submit, and wait 5 to 10 minutes.
- Take the PublicIp from the Outputs tab and connect on port 27017 with MongoDB Compass or
mongosh, using the user and password you set.
To remove the setup: Navigate to CloudFormation Stacks in the AWS Management Console and click "Delete". This will tear down all associated resources cleanly. Backups already in your S3 bucket stay there.
How to restore a MongoDB backup from S3
Practise this before you need it. The steps are short:
- List the backups:
aws s3 ls s3://your-bucket/ --recursiveand pick the one from before the incident. - Copy it to the server:
aws s3 cp s3://your-bucket/path/to/backup ./ - Restore into a scratch database first and check the data with a few queries.
mongorestorecan rename namespaces on the way in with--nsFromand--nsTo. - When you're sure, restore over production. Add
--dropto replace collections instead of merging into them.
The flags depend on how the backup was written (a dump directory, or a single --archive file, often gzipped with --gzip). The mongorestore documentation covers each case. For more detail on the server side, see the MongoDB developer guide, or email Meetrix Support at support@meetrix.io.
What daily backups don't cover: point-in-time recovery
A daily backup taken at 02:00 can't bring back writes from 14:00. If losing up to a day of data is unacceptable, you need point-in-time recovery (PITR), and that means capturing the oplog continuously, not just taking dumps.
- Run MongoDB as a replica set, even a single-member one, so it has an oplog.
- Use a tool that streams the oplog to storage continuously, such as MongoDB Ops Manager or Atlas continuous cloud backup.
- Pair it with EBS snapshots for fast whole-volume recovery.
For most small and mid-sized apps, daily dumps to S3 plus nightly EBS snapshots are a reasonable trade. Be explicit about it, though: write down how much data you could lose, and make sure the business agrees.
MongoDB backup and restore best practices
| Practice | Recommendation |
|---|---|
| Location | Keep backups off the database server, ideally in a bucket only the backup role can write to. |
| Encryption | Turn on default encryption for the bucket (SSE-S3 or SSE-KMS) and block public access. |
| Versioning | Enable S3 versioning so a deleted or overwritten backup can still be recovered. |
| Retention | Keep at least a week of dailies, longer if regulation requires, and expire the rest with a lifecycle rule. |
| Monitoring | Alert when a day passes with no new object in the bucket. Silent backup failures are the common ones. |
| Testing | Restore into a test instance on a schedule, and time it. That number is your real recovery time. |
MongoDB backup to S3: what it costs
Backups are cheap next to the database itself. S3 Standard is about $0.023 per GB per month in us-east-1, uploads from EC2 to S3 in the same region don't carry a transfer charge, and requests cost fractions of a cent. A lifecycle rule that moves backups older than 30 days to a Glacier storage class cuts that further. See S3 pricing for your region. The bigger line is the server: the Marketplace listing shows the software fee per instance type, on top of EC2.
Frequently Asked Questions
How do I back up MongoDB on AWS?
Either take EBS snapshots of the volume, run mongodump on a schedule and copy the output to S3, or use a managed option like Atlas backups. The Meetrix MongoDB AMI does the second for you: daily backups to an S3 bucket you name at launch.
How do I restore a MongoDB backup from S3?
Copy the backup file from the bucket to the server with the AWS CLI, then load it with mongorestore. Restore into a test database first to check it, and only then restore over production, using --drop if you want to replace the existing collections.
Does a daily MongoDB backup give point-in-time recovery?
No. A daily backup can lose up to a day of writes. Point-in-time recovery needs a replica set plus continuous oplog capture, which Atlas continuous backup or MongoDB Ops Manager provide. For many apps, daily dumps plus volume snapshots are enough.
How much does MongoDB backup to S3 cost?
S3 Standard is about $0.023 per GB per month in us-east-1, and uploads from EC2 to S3 in the same region carry no transfer charge. A lifecycle rule that moves backups older than 30 days to Glacier cuts the storage bill further.
What are MongoDB backup and restore best practices?
Keep backups in a different place from the database, encrypt the bucket, keep several days of history, alert when a backup fails, and test a restore regularly. A backup you've never restored is a hope, not a backup.