Skip to content

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