handy backup utility for mongodb in s3 buckets
1.9K
A production-ready MongoDB backup solution with automated scheduling, S3 storage, and comprehensive restore capabilities.
Clone and configure:
git clone <repository-url>
cd cloud-databse-backupper
cp .env.example .env
Configure environment (edit .env):
# MongoDB
MONGODB_URL=mongodb://localhost:27017/your-database
# S3 Storage
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
S3_BUCKET=your-backup-bucket
S3_REGION=us-east-1
# Backup Settings
BACKUP_RETENTION_DAYS=30
FULL_BACKUP_SCHEDULE="0 2 * * 0" # Weekly at 2 AM
INCREMENTAL_BACKUP_SCHEDULE="0 2 * * 1-6" # Daily at 2 AM
Deploy:
docker-compose up -d
# Check system status
docker-compose exec mongodb-backup /scripts/system-status.sh
# Run health check
docker-compose exec mongodb-backup /scripts/health-check.sh
# Test MongoDB connection
docker-compose exec mongodb-backup /scripts/test-mongodb-connection.sh
| Variable | Description | Default |
|---|---|---|
MONGODB_URL | MongoDB connection string | Required |
S3_BUCKET | S3 bucket name | Required |
AWS_ACCESS_KEY_ID | AWS access key | Required |
AWS_SECRET_ACCESS_KEY | AWS secret key | Required |
S3_REGION | AWS region | us-east-1 |
BACKUP_RETENTION_DAYS | Days to keep backups | 30 |
FULL_BACKUP_SCHEDULE | Cron for full backups | 0 2 * * 0 |
INCREMENTAL_BACKUP_SCHEDULE | Cron for incremental | 0 2 * * 1-6 |
# Local MongoDB
MONGODB_URL=mongodb://localhost:27017/myapp
# MongoDB with authentication
MONGODB_URL=mongodb://user:password@host:27017/myapp
# MongoDB Atlas
MONGODB_URL=mongodb+srv://user:[email protected]/myapp
# Replica Set
MONGODB_URL=mongodb://host1:27017,host2:27017/myapp?replicaSet=rs0
# System status
docker-compose exec mongodb-backup /scripts/system-status.sh
# Health check
docker-compose exec mongodb-backup /scripts/health-check.sh
# View logs
docker-compose logs mongodb-backup
docker-compose exec mongodb-backup tail -f /var/log/backup/backup.log
# Trigger full backup
docker-compose exec mongodb-backup /scripts/full-backup.sh
# Trigger incremental backup
docker-compose exec mongodb-backup /scripts/incremental-backup.sh
# List available backups
docker-compose exec mongodb-backup /scripts/list-backups.sh
# Quick restore (latest full backup)
docker-compose exec mongodb-backup /scripts/restore.sh full
# Restore latest incremental backup
docker-compose exec mongodb-backup /scripts/restore.sh incremental
# Restore specific version (when S3 versioning is enabled)
docker-compose exec mongodb-backup /scripts/restore.sh full abc123def456
docker-compose exec mongodb-backup /scripts/restore.sh incremental xyz789ghi012
# Dry run (test restore without making changes)
docker-compose exec mongodb-backup /scripts/restore.sh full --dry-run
docker-compose exec mongodb-backup /scripts/restore.sh full abc123def456 --dry-run
# Verify database after restore
docker-compose exec mongodb-backup /scripts/verify-restore.sh
š For detailed restore procedures, see RESTORE.mdā
šØ For emergency recovery, see DISASTER_RECOVERY_PLAN.mdā
Connection Failed:
# Test MongoDB connection
docker-compose exec mongodb-backup /scripts/test-mongodb-connection.sh
S3 Upload Failed:
# Check S3 permissions and list available backups
docker-compose exec mongodb-backup /scripts/list-backups.sh
Backup Failed:
# Check logs
docker-compose exec mongodb-backup tail -50 /var/log/backup/backup.log
Container Won't Start:
# Check container logs
docker-compose logs mongodb-backup
Getting Specific Version IDs (when S3 versioning is enabled):
# Get version ID for full backup
docker-compose exec mongodb-backup aws s3api head-object \
--bucket s8-db-backups \
--key montabook16-dev-mongodb-full.tar.gz \
--query 'VersionId' --output text
# List all versions of a backup
docker-compose exec mongodb-backup aws s3api list-object-versions \
--bucket s8-db-backups \
--prefix montabook16-dev-mongodb-full.tar.gz
Enable detailed logging:
# Add to .env file
LOG_LEVEL=DEBUG
# Restart container
docker-compose restart mongodb-backup
Required S3 permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::your-bucket",
"arn:aws:s3:::your-bucket/*"
]
}
]
}
Metrics available at /metrics endpoint:
Configure webhooks for backup events:
WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK
WEBHOOK_EVENTS=backup_success,backup_failure,health_check_failure
Logs are automatically rotated:
Old backups are automatically cleaned based on BACKUP_RETENTION_DAYS:
# Manual cleanup
docker-compose exec mongodb-backup /scripts/cleanup-old-backups.sh
# Update to latest version
docker-compose pull
docker-compose up -d
āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā
ā MongoDB ā ā Backup System ā ā AWS S3 ā
ā Database āāāāā⤠(Docker) āāāāāŗā Storage ā
āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāā
ā Monitoring ā
ā & Alerts ā
āāāāāāāāāāāāāāāāāāā
Components:
Production Ready ā | Docker Native š³ | S3 Integrated āļø | Monitoring Enabled š
Content type
Image
Digest
sha256:441dfadf0ā¦
Size
201.5 MB
Last updated
11 months ago
docker pull soolutions/s8-backupper-mongodb