Skip to content

hamed-elfayome/Backup-System

Repository files navigation

Comprehensive Bunny.net Backup System

A robust backup solution for Bunny.net Storage Zones, featuring automated daily backups, interactive restore utility, and comprehensive system health monitoring.

Features

  • Automated daily backups of Bunny.net storage zones
  • Configurable backup schedules and retention policies
  • Parallel file processing for faster backups
  • Detailed logging and error reporting
  • Telegram notifications for backup and system health status
  • Interactive backup restore utility
  • SQLite database for backup history tracking
  • Comprehensive disk health monitoring

Prerequisites

  • Python 3.8+
  • Linux environment (developed and tested on Ubuntu)

Installation

1. System Package Installation

For Ubuntu systems, install required system packages:

sudo apt-get update
sudo apt-get install -y \
    python3-pip \
    mdadm \ # Pre installed
    smartmontools \
    lsblk \ # Pre installed
    rsync \ # Pre installed
    libssl-dev \
    libffi-dev \
    python3-dev

2. Clone Repository

git clone <your-repository-url>
cd backup-system

3. Install Python Dependencies

sudo pip3 install -r requirements.txt

4. Make Scripts Executable

sudo chmod +x main_backup.py
sudo chmod +x main_restore.py
sudo chmod +x disk_health_monitor.py

Configuration

1. Configuration Files

Copy and modify the example configuration files:

cp config.json.example config.json
cp targets.json.example targets.json

Recommended Paths for Ubuntu User

When using the default ubuntu user, recommended paths are:

Backup Directory:     /home/ubuntu/backups
Temporary Directory:  /tmp/backup-system
Log Directory:        /home/ubuntu/backup-logs
Database Path:        /home/ubuntu/backup-system/backups.sqlite

config.json Example

{
  "backup_directory": "/home/ubuntu/backups",
  "temp_directory": "/tmp/backup-system",
  "log_directory": "/home/ubuntu/backup-logs",
  "db_path": "/home/ubuntu/backup-system/backups.sqlite",
  "telegram": {
    "bot_token": "YOUR_TELEGRAM_BOT_TOKEN",
    "chat_id": "YOUR_TELEGRAM_CHAT_ID"
  },
  "disk_space_warning_threshold": 85,
  "always_send_report": true,
  "quiet_when_healthy": false,
  "download_timeout": 120,
  "max_retries": 3,
  "max_workers": 10,
  "health_max_workers": 2
}

targets.json Example

{
  "targets": [
    {
      "id": 1,
      "name": "my-bunny-storage",
      "type": "bunny",
      "credentials": {
        "access_key": "YOUR_BUNNY_ACCESS_KEY",
        "storage_zone": "YOUR_STORAGE_ZONE_NAME"
      },
      "days": ["Mon", "Wed", "Fri"],
      "number_of_shots": 7,
      "active": true
    }
  ]
}

Usage

1. Automated Backups

Set up a cron job for daily backups:

# Open crontab
crontab -e

# Add a line to run backup daily at 3 AM
0 3 * * * /usr/bin/python3 /home/ubuntu/backup-system/main_backup.py

2. Manual Backup

Run backup manually:

python3 main_backup.py

3. Restore Backup

Interactive restore utility with example session:

python3 main_restore.py

Example Restore Session:

Available targets:
1. my-bunny-storage (bunny)

Select target (number): 1

Available backups for my-bunny-storage:
No.   Date                 Time      Status   Size       
1     2024-05-10           14:30:45   ✓       250.5MB
2     2024-05-08           03:15:22   ✓       245.2MB
3     2024-05-05           03:10:11   ✓       252.1MB

Select backup to restore (number): 1

Are you sure you want to restore backup for my-bunny-storage? (yes/no): yes

Starting restore for my-bunny-storage...

[Restore Progress Bar]
✓ Restore completed successfully!
Files restored: 1,234
Total size: 250.5MB
Time taken: 45.2s

4. Disk Health Monitoring

Run disk health check:

python3 disk_health_monitor.py

Logging and Reporting

  • Backup logs: logs/backup.log
  • Restore logs: logs/restore.log
  • Disk health reports: logs/disk_health/
  • Backup history stored in SQLite database

Notifications

Telegram notifications for:

  • Backup status
  • Restore operations
  • Disk health alerts
  • Error conditions

Security Considerations

  • Protect configuration files (config.json)
  • Use secure Telegram bot tokens
  • Limit access to backup directories

Troubleshooting

  1. Check logs for detailed error information
  2. Verify Bunny.net credentials
  3. Ensure sufficient disk space
  4. Check Telegram bot configuration

Requirements

  • Python Libraries:
    • paramiko
    • requests
    • rich
    • psutil
  • System Tools:
    • mdadm
    • smartmontools

About

A robust backup solution for Bunny.net Storage Zones, featuring automated daily backups, interactive restore utility, and comprehensive system health monitoring.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Languages