A simple Bash script to automatically back up all MySQL databases and send them to your Telegram chat.
It also sets up a cron job to run the backup daily at 2 AM and deletes old backups after 7 days.
- β
Full MySQL database backup (compressed
.sql.gz) - β Automatically sent to Telegram as a document
- β
Stored locally in
/root/backupsor custom path - β Cron job for daily backups
- β Auto-deletes backups older than 7 days
- β One-command installer
-
β Telegram Bot Token
π Create here via @BotFather -
β Telegram Chat ID
π Use @userinfobot to get your chat ID -
β MySQL Access (username & password)
Usuallyrootwith MySQL root password -
β A Linux VPS (Tested on Ubuntu 22.04+)
- Backs up all MySQL databases using
mysqldump - Compresses the backup (
gzip) - Sends it via Telegram API
- Deletes backups older than 7 days from local folder
- Adds a cron job that runs the same every night
bash <(curl -s https://raw.githubusercontent.com/zamibd/database-backup-telegram/main/install.sh)Just run and follow the prompts to enter:
- Telegram Bot Token
- Chat ID
- MySQL username
- MySQL password
- (Optional) Backup directory (defaults to
/root/backups)
If you want to save the script manually:
nano install.shPaste the full script from this file, then:
chmod +x install.sh
./install.shOnce installed, this cron job will be added automatically:
0 2 * * * bash /full/path/to/install.sh >> /var/log/mysql_telegram_backup.log 2>&1
You can verify it by running:
crontab -lDefault: /root/backups/
Files: all_db_backup_YYYY-MM-DD.sql.gz
Older than 7 days? Theyβre automatically deleted.
If you face any issues or want to customize:
- Open an issue on GitHub
- Or contact the script author @zamibd
--- MySQL Telegram Backup: Fresh Setup ---
Enter your Telegram Bot Token: 123456...
Enter your Telegram Chat ID: 987654321
Enter your MySQL Username (e.g., root): root
Enter your MySQL Password:
Enter full path for backup directory (default: /root/backups):
β
Configuration saved
β
Cronjob added to run daily at 2 AM
--> Running backup now...
β
Backup complete!Enjoy secure, automated backups. π‘οΈπ¦