Skip to content

Barshap-Bhanja/automated-db-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Automated MongoDB Backup to Cloudflare R2

πŸ“Œ Overview

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.


πŸš€ Features

  • βœ… 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

πŸ› οΈ Tech Stack

  • MongoDB (Database)
  • Bash scripting (Automation)
  • AWS CLI (Upload to R2)
  • GitHub Actions (CI/CD for scheduling)
  • Cloudflare R2 (Backup storage)

πŸ“‚ Project Structure

.
β”œβ”€β”€ backup.sh          # Script for backup & upload
β”œβ”€β”€ restore.sh         # Script to restore from latest backup
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── db-backup.yml   # GitHub Actions workflow
└── README.md

βš™οΈ Setup Instructions

  1. Clone the Repository

    git clone https://github.com/your-username/automated-db-backup.git
    cd automated-db-backup
  2. Configure Cloudflare R2

    • Create a bucket in Cloudflare R2
    • Get Access Key and Secret Key
    • Configure AWS CLI:
      aws configure
  3. Run Backup Manually

    chmod +x backup.sh
    ./backup.sh
  4. Schedule with Cron (Server Option)

    crontab -e

    Add:

    0 */12 * * * /home/ubuntu/backup.sh >> /home/ubuntu/backup.log 2>&1
    
  5. GitHub Actions (CI/CD Option) Add repository secrets in GitHub:

    • DB_URI
    • DB_NAME
    • R2_BUCKET
    • R2_ENDPOINT
    • R2_ACCESS_KEY
    • R2_SECRET_KEY

πŸ”„ Restore Database

chmod +x restore.sh
./restore.sh

πŸ‘¨β€πŸ’» Author

Barshapriyadarshini Bhanja

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages