Skip to content

Fully automated cloud backup and disaster recovery system for static websites, using Flask, Python, and Backblaze B2 cloud storage. Features include one-click restore and an always-available admin panel.

Notifications You must be signed in to change notification settings

nidhi-shree/automated-cloud-backup

Repository files navigation

Automated Cloud Backup & Disaster Recovery System

Python Flask Backblaze B2 Github pages

This project is a fully automated cloud-backup and disaster-recovery system designed to protect a static website and supporting files using Backblaze B2 Cloud Storage, Flask, and Python automation scripts.

It provides:

  • Automatic scheduled backups
  • Instant disaster simulation
  • One-click website restoration
  • Real-time monitoring dashboard
  • GitHub Pages hosting for the public website (/docs)
  • A persistent /admin control panel that cannot be deleted

πŸ“Œ Table of Contents

  1. Project Overview
  2. System Architecture
  3. Project Structure
  4. Features
  5. Technologies Used
  6. Setup Instructions
  7. Environment Variables
  8. Running the Project
  9. Backup Workflow
  10. Disaster Simulation
  11. Restore Workflow
  12. Monitoring & Logging
  13. GitHub Pages Deployment
  14. Admin Control Panel
  15. Future Improvements
  16. Conclusion

1. Project Overview

This project solves a real-world problem:
➑ what happens if your website files are accidentally deleted or corrupted?

To ensure your website always recovers, this system automatically:

  • Backs up `/docs(website) to Backblaze B2
  • Monitors backup status and logs it
  • Provides a web interface to simulate disaster and recover files instantly
  • Restores the site from B2 on demand and redeploys via git push

It is fully automated and runs as a scheduled background job.


πŸ–ΌοΈ System Screenshots

Here are key views of the automated backup and recovery system in action:

Admin Control Panel Live Content Editing
Admin Panel View Live Edit View
Website Homepage Restore After Disaster
Homepage View Restore Success View

2. System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       GitHub Pages        β”‚
β”‚  Hosts the /docs website  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Local App         β”‚
β”‚  Flask + Python Scripts   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Admin Dashboard       β”‚
β”‚  /admin (never deleted)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Automated Backup Scripts  β”‚
β”‚ backup_to_b2.py           β”‚
β”‚ restore_from_b2.py        β”‚
β”‚ disaster_recovery.py      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
       Cloud Storage  
     Backblaze B2 Bucket

3. Project Structure

automated-cloud-backup/
β”‚
β”œβ”€β”€ docs/                        # Public website served by GitHub Pages
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ about.html
β”‚   β”œβ”€β”€ contact.html
β”‚   β”œβ”€β”€ css/
β”‚   β”œβ”€β”€ js/
β”‚   └── data/
β”‚
β”œβ”€β”€ server.py                    # Flask web server + Admin dashboard
β”œβ”€β”€ backup_to_b2.py              # Uploads latest backup to Backblaze B2
β”œβ”€β”€ restore_from_b2.py           # Restores from cloud backup
β”œβ”€β”€ disaster_recovery.py         # Deletes docs/ to simulate disaster
β”œβ”€β”€ monitor_backups.py           # Logs backup status & timestamps
β”œβ”€β”€ metrics.json                 # Stores backup metrics
β”œβ”€β”€ backup.log                   # Log file for monitoring
β”‚
β”œβ”€β”€ requirements.txt             # Python dependencies
β”œβ”€β”€ .env                         # API keys (ignored in Git)
└── README.md                    # Project documentation

4. Features

βœ… Automated Cloud Backups

Automatically zips the /docs folder and uploads it to Backblaze B2.

βœ… Disaster Simulation

One-click "⚠ Simulate Disaster" deletes the entire website folder.

βœ… Instant Recovery System

One-click "πŸ” Restore Website" downloads the backup and recreates the website.

βœ… Admin Dashboard

Accessible at: http://localhost:5000/admin

Shows:

  • Last backup time
  • Backup status
  • Restore button
  • Disaster simulation button
  • Backup logs

βœ… Scheduled Backups

Using Windows Task Scheduler / Cron.

βœ… Full Logging & Monitoring

Stores logs in:

  • backup.log
  • metrics.json

βœ… GitHub Pages Hosting

The /docs folder is served publicly via:
https://nidhi-shree.github.io/automated-cloud-backup/

βœ… Frontend Editing (Live content via content.json)

The site now loads visible text from docs/data/content.json. A floating toolbar is available on every page:

  • Edit Mode: toggles inline editing of content
  • Save Changes: writes your edits back to docs/data/content.json.
  • Backup: triggers automatic backup to Backblaze B2
  • Restore: triggers restore from Backblaze B2
  • Simulate Disaster: copies a command to delete docs/ locally (demo)

How saving works:

  • The site saves changes via the Flask backend to docs/data/content.json.
  • Saving automatically triggers a backup to Backblaze B2.
  • Either way, the updated content.json is a normal file inside docs/ and is included in backups.

Data format (docs/data/content.json):

{
  "title": "Disaster Recovery Dashboard",
  "tagline": "Automated Cloud Backup & Recovery Demo",
  "about": "This project demonstrates how to automatically back up and restore a website using Backblaze B2 and GitHub Pages.",
  "features": [
    { "title": "Automatic Backup", "description": "All site files are synced to Backblaze B2 cloud storage." },
    { "title": "One-Click Restore", "description": "Recover from simulated disasters instantly." },
    { "title": "Editable Frontend", "description": "Edit website content directly from your browser." }
  ],
  "contact": {
    "email": "demo@example.com",
    "message": "Contact us to learn more about automated disaster recovery systems."
  }
}

πŸš€ Quick Start

1-Minute Setup

# 1. Clone and install
git clone <repository-url>
cd automated-cloud-backup
pip install -r requirements.txt

# 2. Configure environment
cp env.example .env
# Edit .env with your Backblaze B2 credentials

# 3. Start the system
python server.py

Quick Demo

  1. 🌐 Open: http://localhost:5000
  2. πŸ–‹οΈ Edit: Click "Edit Mode" and modify content
  3. πŸ’Ύ Save: Changes auto-backup to Backblaze B2
  4. 🚨 Test: Click "Simulate Disaster"
  5. πŸ”„ Recover: Click "Restore" - site recovers in 60 seconds!

πŸ” Security Setup (Recommended)

# Add to your .env file
ADMIN_TOKEN=your_secure_random_token_here

# Optional: Email alerts
SMTP_SERVER=smtp.gmail.com
SMTP_USERNAME=your_email@gmail.com
SMTP_PASSWORD=your_app_password
ALERT_EMAIL=admin@yourdomain.com

πŸ›‘οΈ Security Features: Token auth, encrypted storage, audit logs


πŸ”Œ API Reference

Public Endpoints

GET  /              # Website interface
GET  /health        # System health check
GET  /metrics       # Real-time metrics

Authenticated Endpoints (Require ADMIN_TOKEN)

POST /save-content      # Save and backup content
POST /backup            # Manual backup trigger
POST /restore           # Disaster recovery
POST /simulate-disaster # Safe disaster testing

Authentication

# Include in request headers
Authorization: Bearer your_admin_token_here
  • GET / - Serve the website
  • GET /health - Health check endpoint
  • GET /metrics - Backup metrics and statistics
  • POST /save-content - Save content and trigger backup (auth required)
  • POST /backup - Manual backup trigger (auth required)
  • POST /restore - Restore from backup (auth required)
  • POST /simulate-disaster - Disaster simulation (auth required)

πŸ”§ Troubleshooting

🚨 Common Issues

❌ "Bucket not found" Error

Solution:

  • Verify bucket exists in Backblaze B2 console
  • Check B2_BUCKET_NAME in .env matches exactly
  • Ensure bucket is in the correct region
πŸ” "Authentication failed" Error

Solution:

  • Verify B2_APPLICATION_KEY_ID and B2_APPLICATION_KEY in .env
  • Check App Key has required capabilities: listBuckets, readFiles, writeFiles, listFiles
  • Generate new App Key if needed
πŸ“ "No files uploaded" Warning

Solution:

  • Check SITE_DIR path in .env is correct
  • Verify docs/ directory contains files
  • Check file permissions

Common Issues

  1. "Bucket not found": Ensure your bucket exists in Backblaze and the name matches exactly
  2. "Authentication failed": Double-check your B2_APPLICATION_KEY_ID and B2_APPLICATION_KEY
  3. "Permission denied": Ensure your App Key has the required capabilities (listBuckets, readFiles, writeFiles, listFiles)
  4. "No files uploaded": Check that your SITE_DIR contains files and the path is correct
  5. "Authentication required": Set ADMIN_TOKEN in .env or click the Auth button

πŸ” Debug Commands

# Configuration check
python -c "from dotenv import load_dotenv; load_dotenv(); import os; print('βœ… B2 Bucket:', os.getenv('B2_BUCKET_NAME'))"

# Connection test
python -c "from backup_to_b2 import init_b2; print('βœ… B2 Connection:', init_b2())"

# Log monitoring
tail -f backup.log              # Backup operations
tail -f monitor.log             # Health monitoring
tail -f disaster_recovery.log   # Recovery operations

5. Technologies Used

Component Technology
Backend Server Flask (Python)
Cloud Storage Backblaze B2
Automation Python scripts
Frontend HTML, CSS, JS
Hosting GitHub Pages
Logging backup.log + metrics.json
Scheduling Windows Task Scheduler / Cron

6. Setup Instructions

1️⃣ Install Python

Make sure Python 3.10+ is installed.

2️⃣ Create Virtual Environment

python -m venv venv

Activate: Windows: venv\Scripts\activate

Linux/Mac: source venv/bin/activa

3️⃣ Install Dependencies

pip install -r requirements.txt

### 4️⃣ Create .env File

Add:

B2_APPLICATION_KEY_ID=xxxx
B2_APPLICATION_KEY=xxxx
B2_BUCKET_NAME=xxxx

6. Environment variables

Variable Description
B2_APPLICATION_KEY_ID Backblaze key ID
B2_APPLICATION_KEY Backblaze private key
B2_BUCKET_NAME Your bucket name: disaster-recovery-bucket

8. Running the Project

Start the Flask server:

python server.py

Admin panel: http://localhost:5000/admin

Public site (when running locally): http://localhost:5000/


9. Backup Workflow

πŸ” Steps performed by backup_to_b2.py:

  • Zip the /docs folder
  • Upload to Backblaze B2
  • Update metrics.json
  • Append to backup.log

Backups run automatically through:

  • Scheduled tasks
  • Manual trigger from admin panel

10. Disaster Simulation

The /admin dashboard has: πŸ’₯ Simulate Disaster

This will:

  • Completely delete the /docs folder
  • Website becomes unavailable
  • Admin panel still works (because it is outside /docs)

This simulates real-world situations:

  • Accidental deletion
  • Corrupted deployment
  • Malware / ransomware deletion
  • Developer mistakes

11. Restore Workflow

When "Restore Website" is clicked:

  • Latest backup is downloaded from Backblaze B2
  • Unzipped into /docs
  • Website becomes live again instantly

This demonstrates disaster recovery concepts:

  • Recovery Time Objective (RTO)
  • Recovery Point Objective (RPO)

12. Monitoring & Logging

backup.log shows:

text [2025-11-12] Backup successful (2.4MB) [2025-11-13] Backup failed: network error metrics.json stores:

json { "last_backup": "2025-11-14 09:33:12", "status": "SUCCESS", "backup_size": "2.4 MB" } These metrics are displayed in /admin.


13. GitHub Pages Deployment

Since GitHub Pages needs either:

  • /docs folder
  • root /

βœ” Deployed from master branch β†’ /docs folder

GitHub Pages website here: https://nidhi-shree.github.io/automated-cloud-backup/

GitHub Pages serves ONLY /docs site(static). Admin panel is local-only.


14. Admin Control Panel

Admin Panel URL: http://localhost:5000/admin

Admin Panel Buttons:

Button Function
Backup Now Triggers backup_to_b2.py
Simulate Disaster Deletes entire /docs folder
Restore Website Restores from cloud backup
View Logs Shows last N log entries

Admin panel is never deleted, even during disaster, because it lives in Flask templates folder β€” NOT inside /docs.


15. Future Improvements

Add user authentication for admin panel

E-mail alerts on backup failure

Versioned backups with timestamps

Real-time WebSocket monitoring

Multi-cloud backup (AWS S3 + Azure Blob)

CLI tool for automation


16. Conclusion

This project demonstrates:

Real-world cloud backup automation

Disaster recovery engineering

Flask web app development

GitHub Pages deployment

Cloud storage integration

Scheduled task automation

Monitoring/logging systems


About

Fully automated cloud backup and disaster recovery system for static websites, using Flask, Python, and Backblaze B2 cloud storage. Features include one-click restore and an always-available admin panel.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published