Scheduled MongoDB and Atlas backups to cloud storage
A mongodump archive of your MongoDB database, Atlas included, saved every night or every few hours into Google Drive, Amazon S3, OneDrive or any other cloud.
The do-it-yourself way: mongodump and cron
On a machine that is always on, this is the usual script. Putting the connection string in a config file, rather than on the command line, keeps the password out of the process list:
# mongo.yaml (chmod 600)
uri: mongodb+srv://backup:password@cluster0.example.mongodb.net/shop
#!/usr/bin/env bash
set -euo pipefail
stamp=$(date +%Y-%m-%d-%H%M%S)
file="/var/backups/shop-$stamp.archive.gz"
mongodump --config=/etc/backup/mongo.yaml --archive | gzip > "$file"
rclone copy "$file" remote:db-backups/
find /var/backups -name 'shop-*.archive.gz' -mtime +14 -delete
It has the same weak spots as any cron backup: nobody hears when it fails, the copies in the cloud are never pruned, and the machine has to be up at 2 a.m.
Steps
- Sign in, open Databases and press Connect a database. Choose MongoDB, or your hosting service by name.
- Paste the connection string (
mongodb+srv://user:password@cluster0.example.mongodb.net/dbnamefrom Atlas, ormongodb://with one or more servers), or fill in the server, database, username and password one by one. - If the database only answers on its own server, fill in the SSH server fields too; it is then reached through that server, and the database address is usually
localhost. - Press Schedule on its card. Choose the cloud and folder, how many backups to keep (1 to 365), and how often: every 6 hours, every 12 hours, every day, every Sunday or on the 1st of every month.
- Save. The first backup starts at once, and its progress shows in the job list.
What each backup is
- A
mongodump --archiveof the database, gzipped as it streams: one dated file such asshop-2026-11-04-020000.archive.gz, whichmongorestorereads anywhere. - Atlas's
mongodb+srv://string is understood as it is, and a replica set is several servers separated by commas. - Name one collection (or
database.collection) to back up only that. For several, make a backup for each. - The oldest backups past the number you keep are removed after each good run.
Encrypted backups
Give the database a backup passphrase (12 characters or more) and every backup is encrypted with AES-256 before it leaves our server; its name gains .enc. The cloud you save into then holds nothing readable. To open one on your own computer, with the OpenSSL that comes with macOS, Linux and Git for Windows:
openssl enc -d -aes-256-cbc -pbkdf2 -iter 600000 -in shop-2026-11-04-020000.archive.gz.enc -out shop-2026-11-04-020000.archive.gz
Keep the passphrase somewhere safe. Without it nobody, including us, can open the backups.
Restoring a backup
From the app: press Restore on the database's card and pick a backup. Tick Drop each collection before restoring it to replace collections rather than add to them, type the database's name to confirm, and start.
By hand, with MongoDB's database tools:
gunzip -c shop-2026-11-04-020000.archive.gz | mongorestore --uri="mongodb+srv://user@cluster0.example.mongodb.net" --archive --drop
MongoDB Atlas
- Make a database user with the read role on the database (restores need readWrite), under Database Access.
- Add our server's address under Network Access, IP Access List.
- Copy the connection string from Connect, Drivers, and paste it with the password filled in.
Atlas keeps its own snapshots on paid clusters, inside your Atlas account. A copy in storage you own is what is left if that account or project is closed, compromised or deleted.
Limits
- A backup is the data at one moment, not a continuous replica or point-in-time recovery.
- A backup stops after 2 hours, or past 20 GB compressed, unless the operator has changed those limits.
- Each backup's size counts towards your transfer allowance.
Questions
Is a backup of a busy replica set consistent?
Each collection is read as it is when mongodump reaches it, so writes during the backup can land in one collection and not another. For most applications that is fine; for an exact moment in time, use Atlas's own snapshots alongside.
Can I back up several collections in one run?
One collection per backup, or the whole database. Make a schedule per collection if you want only some of them.
Try it
Prepaid: 30 GB free, then 500 GB for ₹100 or 2,500 GB for ₹500, each valid a year. No card is asked for to start.