This repository contains a set of Bash scripts for automating backups on multiple VPS servers. The system securely creates, synchronizes, and stores backups using rsync and rclone, with Telegram notifications for status updates.
- 📌 For detailed setup and usage of
rclone, see: Rclone - 📌 If you need a reliable VPS for hosting your backups, you can find options on: VPS & VDS Hosting
This script runs directly on each VPS to:
- Create daily, weekly, and monthly backups of website files and MySQL databases.
- Compress and organize backups into a structured directory.
- Ensure old backups are rotated according to retention policies.
- Send notifications to Telegram about backup status.
This script can work autonomously on any VPS to handle local backup generation.
This script runs on a centralized backup server to:
- Connect via SSH to multiple VPS servers and fetch backups using
rsync. - Store retrieved backups in a local directory (
/root/google_sync/). - Upload backups to Google Drive using
rclone, ensuring no files are lost. - Keep deleted backups in a separate folder (
old_backups/) on Google Drive for manual removal. - Send a Telegram notification after sync completion.
A configuration file that stores environment variables such as:
- MySQL credentials (if
.my.cnfis not used) - Telegram bot token and chat ID
git clone https://github.com/darkfire13/vps-backup-automation.git
cd vps-backup-automationCreate and edit /root/.backup_env:
nano /root/.backup_envExample configuration:
TELEGRAM_BOT_TOKEN="your_telegram_bot_token"
TELEGRAM_CHAT_ID="your_chat_id"
DB_USER="your_mysql_user"
DB_PASS="your_mysql_password"Generate and copy SSH keys to all VPS servers:
ssh-keygen -t ed25519 -C "backup@server" -f ~/.ssh/id_ed25519
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@your_vps_nameEnsure each VPS is added to /etc/hosts with a human-readable name.
30 4 * * * /bin/bash /root/backup_script_vps.sh >> /var/log/backup.log 2>&10 6 * * * /bin/bash /root/sync_vps_backups.sh >> /var/log/backup_sync.log 2>&1- The
backup_script_vps.shcan work independently on any VPS to generate backups. - The
sync_vps_backups.shfetches all backups from multiple VPS and uploads them to Google Drive. - Deleted backups are moved to
old_backups/on Google Drive instead of being permanently deleted. - Telegram notifications are sent in case of success or failure.