Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🛡️ MySQL Telegram Backup Script

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.


🚀 What You Get

  • ✅ Full MySQL database backup (compressed .sql.gz)
  • ✅ Automatically sent to Telegram as a document
  • ✅ Stored locally in /root/backups or custom path
  • ✅ Cron job for daily backups
  • ✅ Auto-deletes backups older than 7 days
  • ✅ One-command installer

🔧 What You Need

  1. ✅ Telegram Bot Token
    👉 Create here via @BotFather

  2. ✅ Telegram Chat ID
    👉 Use @userinfobot to get your chat ID

  3. ✅ MySQL Access (username & password)
    Usually root with MySQL root password

  4. ✅ A Linux VPS (Tested on Ubuntu 22.04+)


🧠 How It Works

  • 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

📥 Install with One Command

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)

📝 Manual Install (via nano)

If you want to save the script manually:

nano install.sh

Paste the full script from this file, then:

chmod +x install.sh
./install.sh

⏰ Cron Job

Once 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 -l

📁 Backup Location

Default: /root/backups/
Files: all_db_backup_YYYY-MM-DD.sql.gz

Older than 7 days? They’re automatically deleted.


🙋 Support

If you face any issues or want to customize:

  • Open an issue on GitHub
  • Or contact the script author @zamibd

✅ Example Output on Install

--- 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. 🛡️📦

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages