A robust backup solution for Bunny.net Storage Zones, featuring automated daily backups, interactive restore utility, and comprehensive system health monitoring.
- 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
- Python 3.8+
- Linux environment (developed and tested on Ubuntu)
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-devgit clone <your-repository-url>
cd backup-systemsudo pip3 install -r requirements.txtsudo chmod +x main_backup.py
sudo chmod +x main_restore.py
sudo chmod +x disk_health_monitor.pyCopy and modify the example configuration files:
cp config.json.example config.json
cp targets.json.example targets.jsonWhen 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
{
"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": [
{
"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
}
]
}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.pyRun backup manually:
python3 main_backup.pyInteractive restore utility with example session:
python3 main_restore.pyExample 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
Run disk health check:
python3 disk_health_monitor.py- Backup logs:
logs/backup.log - Restore logs:
logs/restore.log - Disk health reports:
logs/disk_health/ - Backup history stored in SQLite database
Telegram notifications for:
- Backup status
- Restore operations
- Disk health alerts
- Error conditions
- Protect configuration files (config.json)
- Use secure Telegram bot tokens
- Limit access to backup directories
- Check logs for detailed error information
- Verify Bunny.net credentials
- Ensure sufficient disk space
- Check Telegram bot configuration
- Python Libraries:
- paramiko
- requests
- rich
- psutil
- System Tools:
- mdadm
- smartmontools