This project automates the process of backing up a MongoDB database every 12 hours and uploading the backup to Cloudflare R2 storage.
It also provides a script to restore the database from the latest backup.
- β
Automated database backup using
mongodump
- β
Compression into
.tar.gz
archive - β Uploads backup files to Cloudflare R2 using AWS CLI
- β Runs automatically via Cron jobs or GitHub Actions
- β Restore script to recover database from latest backup
- MongoDB (Database)
- Bash scripting (Automation)
- AWS CLI (Upload to R2)
- GitHub Actions (CI/CD for scheduling)
- Cloudflare R2 (Backup storage)
.
βββ backup.sh # Script for backup & upload
βββ restore.sh # Script to restore from latest backup
βββ .github/
β βββ workflows/
β βββ db-backup.yml # GitHub Actions workflow
βββ README.md
-
Clone the Repository
git clone https://github.com/your-username/automated-db-backup.git cd automated-db-backup
-
Configure Cloudflare R2
- Create a bucket in Cloudflare R2
- Get Access Key and Secret Key
- Configure AWS CLI:
aws configure
-
Run Backup Manually
chmod +x backup.sh ./backup.sh
-
Schedule with Cron (Server Option)
crontab -e
Add:
0 */12 * * * /home/ubuntu/backup.sh >> /home/ubuntu/backup.log 2>&1
-
GitHub Actions (CI/CD Option) Add repository secrets in GitHub:
DB_URI
DB_NAME
R2_BUCKET
R2_ENDPOINT
R2_ACCESS_KEY
R2_SECRET_KEY
chmod +x restore.sh
./restore.sh
Barshapriyadarshini Bhanja