A production-ready Docker container that automatically backs up MongoDB databases with multiple backup schedules, comprehensive web dashboard, and minimal impact on database performance.
- Multi-Schedule Backups: Daily, weekly, monthly, and yearly backup schedules
- Web Dashboard: Real-time backup monitoring and history viewing
- Production-Safe: Uses
--readPreference=secondaryPreferredand--numParallelCollections=1for minimal database load - Smart Retention: Configurable backup retention policies with automatic cleanup
- Non-Overlapping Backups: Prevents concurrent backup operations
- Organized Storage: Separate folders for daily/weekly/monthly/yearly backups
- Detailed Tracking: SQLite database tracks backup metadata, duration, and statistics
- Backup-Specific Logging: Each backup stores its own detailed logs in the database
- Missing Backup Detection: Automatically creates missing weekly/monthly/yearly backups on startup
- Resource Limited: Configurable CPU and memory limits
- Unraid Compatible: Easy deployment on Unraid servers
git clone git@github.com:jaaywags/automated-mongo-backup.git
cd automated-mongo-backup
cp .env.example .envEdit .env file.
# Using pre-built image from Docker Hub
docker-compose up -d
# Or build locally by uncommenting the build line in docker-compose.ymlAccess the web dashboard at http://localhost:3000 (or your server IP) to:
- Monitor Current Backups: See real-time backup progress
- View Backup History: Browse recent backups by type (daily/weekly/monthly/yearly)
- Check Statistics: View success rates, durations, and storage usage
- Access Logs: View detailed logs for each backup (success or failure)
- Download Backups: Download backup files as compressed tar.gz archives
- Configure Display: Show 5-30 recent backups per type
| Variable | Description | Default | Required |
|---|---|---|---|
MONGO_CONNECTION_STRING |
MongoDB connection URI | - | β |
DAILY_BACKUP_INTERVAL_MINUTES |
Daily backup frequency in minutes | 60 |
β |
MAX_DAILY_BACKUPS |
Max daily backups to keep (-1 = unlimited) | 24 |
β |
NUMBER_OF_WEEKLY_BACKUPS |
Weekly backups distributed over 7 days | 7 |
β |
MAX_AGE_OF_WEEKLY_BACKUPS |
Max age of weekly backups (weeks) | 4 |
β |
NUMBER_OF_MONTHLY_BACKUPS |
Monthly backups (1st of month) | 12 |
β |
MAX_AGE_OF_MONTHLY_BACKUPS |
Max age of monthly backups (months) | 12 |
β |
NUMBER_OF_YEARLY_BACKUPS |
Yearly backups (Jan 1st) | 5 |
β |
MAX_AGE_OF_YEARLY_BACKUPS |
Max age of yearly backups (years) | 5 |
β |
BACKUP_PATH |
Container path for backups | /backups |
β |
BACKUP_HOST_PATH |
Backup location on host machine | ./backups |
β |
WEB_UI_PORT |
Web dashboard port | 3000 |
β |
TIMEZONE |
Timezone for scheduling | UTC |
β |
# Standard MongoDB
MONGO_CONNECTION_STRING=mongodb://username:password@localhost:27017/mydb
# MongoDB with authentication database
MONGO_CONNECTION_STRING=mongodb://username:password@localhost:27017/mydb?authSource=admin
# MongoDB Atlas
MONGO_CONNECTION_STRING=mongodb+srv://username:password@cluster.mongodb.net/mydb
# MongoDB Replica Set
MONGO_CONNECTION_STRING=mongodb://username:password@host1:27017,host2:27017,host3:27017/mydb?replicaSet=rs0- Install Docker Compose Manager plugin from Community Applications
- Create a new stack with the provided
docker-compose.yml - Update environment variables in the compose file
- Set volume path to your preferred backup location (e.g.,
/mnt/user/backups/mongodb)
- Go to Docker tab in Unraid
- Click Add Container
- Configure as follows:
Name: mongodb-backup
Repository: jaaywags/automated-mongo-backup
Network Type: Bridge (or Host if MongoDB is on Unraid)
Environment Variables:
- MONGO_CONNECTION_STRING: mongodb://user:pass@192.168.1.100:27017/mydb
- DAILY_BACKUP_INTERVAL_MINUTES: 60
- MAX_DAILY_BACKUPS: 24
- NUMBER_OF_WEEKLY_BACKUPS: 7
- MAX_AGE_OF_WEEKLY_BACKUPS: 4
- WEB_UI_PORT: 3000
- TIMEZONE: America/New_York
Volume Mappings:
- Container Path: /backups
- Host Path: /mnt/user/backups/mongodb
- Access Mode: Read/Write
Port Mappings:
- Container Port: 3000
- Host Port: 3000
- Protocol: TCP
Resource Limits:
- CPU: 0.5
- Memory: 512MB
docker run -d \
--name mongodb-backup \
--restart unless-stopped \
-e MONGO_CONNECTION_STRING="mongodb://user:pass@host:27017/mydb" \
-e DAILY_BACKUP_INTERVAL_MINUTES=60 \
-e MAX_DAILY_BACKUPS=24 \
-e NUMBER_OF_WEEKLY_BACKUPS=7 \
-e WEB_UI_PORT=3000 \
-v /mnt/user/backups/mongodb:/backups \
-p 3000:3000 \
--cpus="0.5" \
--memory="512m" \
mongo-backupBackups are organized as follows:
/backups/
βββ daily/
β βββ 20250902_141500_MyDatabase_daily/
β β βββ MyDatabase/
β β β βββ users.bson
β β β βββ users.metadata.json
β β β βββ orders.bson
β β β βββ orders.metadata.json
β β βββ oplog.bson
β βββ 20250902_151500_MyDatabase_daily/
βββ weekly/
β βββ 20250901_000000_MyDatabase_weekly/
βββ monthly/
β βββ 20250801_000000_MyDatabase_monthly/
βββ yearly/
β βββ 20250101_000000_MyDatabase_yearly/
βββ backup_metadata.db
βββ backup.log
The backup system uses several MongoDB-specific optimizations:
--readPreference=secondaryPreferred: Routes reads to secondary nodes when available--numParallelCollections=1: Limits concurrent collection backups--quiet: Reduces verbose output for cleaner logs- Resource limits: Prevents backup process from overwhelming the system
- Runs as non-root user (
backup:nodejs) - Connection strings are redacted in logs
- No hardcoded credentials
Check backup status:
# View logs
docker logs mongodb-backup
# Check backup files
ls -la /mnt/user/backups/mongodb/
# Monitor resource usage
docker stats mongodb-backupConnection Failed
# Test MongoDB connectivity
docker exec mongodb-backup mongosh "your-connection-string" --eval "db.runCommand('ping')"Permission Denied
# Fix backup directory permissions
sudo chown -R 1001:1001 /mnt/user/backups/mongodbHigh Memory Usage
- Reduce
BACKUP_INTERVAL_MINUTESfor smaller, more frequent backups - Increase memory limit in docker-compose.yml
- Consider backing up specific collections instead of entire database
- Container logs:
docker logs mongodb-backup - Backup logs:
/mnt/user/backups/mongodb/backup.log
To restore from a backup:
# Extract downloaded backup first
tar -xzf 20250902_141500_MyDatabase.tar.gz
# Restore entire database
mongorestore --uri="mongodb://user:pass@host:27017" ./20250902_141500_MyDatabase/
# Restore specific collection
mongorestore --uri="mongodb://user:pass@host:27017" --collection=users ./20250902_141500_MyDatabase/MyDatabase/users.bsonMIT License - see LICENSE file for details.
