Skip to main content

Back up MongoDB to Filebase

mongodump can produce a single-file archive that streams cleanly to Filebase.

One-off backup

mongodump --uri="mongodb://user:pass@host/db" --archive --gzip \
| aws --endpoint https://s3.filebase.io s3 cp - \
s3://my-db-backups/mongo/db-$(date +%Y%m%d-%H%M%S).archive.gz

--archive writes a single archive to stdout; --gzip compresses inline.

Restore

aws --endpoint https://s3.filebase.io s3 cp \
s3://my-db-backups/mongo/db-20260501-120000.archive.gz - \
| mongorestore --uri="mongodb://user:pass@host/db" --archive --gzip

Daily cron job

/usr/local/bin/mongo-backup.sh
#!/bin/bash
set -euo pipefail

BUCKET="my-db-backups"
DB="mydb"
DATE=$(date +%Y%m%d-%H%M%S)

export AWS_ACCESS_KEY_ID="$FILEBASE_KEY"
export AWS_SECRET_ACCESS_KEY="$FILEBASE_SECRET"

mongodump \
--uri="$MONGO_URI" \
--archive --gzip \
| aws --endpoint https://s3.filebase.io s3 cp - \
"s3://${BUCKET}/mongo/${DB}-${DATE}.archive.gz"

Schedule with cron and ensure MONGO_URI is in /etc/default/mongo-backup or similar (not on the command line).

Specific collections

mongodump --uri="..." --db=mydb --collection=users --archive --gzip \
| aws --endpoint https://s3.filebase.io s3 cp - \
s3://my-db-backups/mongo/users-$(date +%Y%m%d).archive.gz

Physical backups

For large clusters, MongoDB Ops Manager or Percona Backup for MongoDB can target S3-compatible storage with the standard endpoint/region. These produce hot, file-system-level backups that restore much faster than mongorestore.

What's next