This project automates the backup of a MongoDB database every 12 hours and uploads it to an AWS S3 bucket. It also provides a script to restore the latest backup from S3.
- Automated Database Backup: Uses
mongodump
to create a backup. - Upload to S3: Utilizes
aws-cli
to store backups in S3. - GitHub Actions Integration: Scheduled workflow to run every 12 hours.
- Restore Script: Downloads and restores the latest backup from S3.
- An AWS account with an S3 bucket.
- A server (AWS EC2 or any Linux machine) with MongoDB installed, for installation refer : (https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/)
- AWS CLI installed and configured (
aws configure
). - GitHub repository for CI/CD (optional, for GitHub Actions method).
Run the seed.sh
script to add sample data:
chmod +x seed.sh
./seed.sh
-
Install AWS CLI and configure it:
-
To Execute a backup script (
backup.sh
):./backup.sh
-
Add a cron job to schedule the backup every 12 hours:
crontab -e
Add this line:
0 */12 * * * /home/ubuntu/backup.sh >> /home/ubuntu/backup.log 2>&1
Run the restore.sh
script to download and restore the latest backup:
chmod +x restore.sh
./restore.sh
This project is part of vsbuidev's Roadmap DevOps projects.