| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
db_backup_telegram.php is a PHP-based multi-database backup script that allows you to automate backups for MySQL/MariaDB databases. It supports compression, Telegram upload notifications, retention management, emoji captions, and robust logging.
Clone the repository or download the db_backup_telegram.php file.
git clone https://github.com/BaseMax/database-auto-backup-telegram.gitEnsure you have a Telegram bot. If not, create one by talking to BotFather on Telegram. You will need the bot token and chat ID for sending backup files.
Configure the script:
Example:
$config = [
'databases' => [
[
'name' => 'your_db_name',
'user' => 'your_db_user',
'pass' => 'your_db_password',
'host' => 'localhost',
'port' => 3306
]
],
'output_dir' => __DIR__ . '/backups',
'use_mysqldump' => true, // Enable mysqldump or fallback to PHP PDO
'compression' => 'gz', // Supported: gz, bz2, zip
'telegram' => [
'bot_token' => 'your_bot_token',
'chat_id' => 'your_chat_id',
'caption' => 'Auto DB Backup'
],
'retention_days' => 30, // Retain backups for 30 days
'log_file' => __DIR__ . '/backups/backup.log',
];Make sure your web server or PHP process has write permissions to the output directory.
Run the script manually:
You can run the script directly from the command line or via a web server. To run the script manually, execute:
php db_backup_telegram.phpAutomate backups with a cron job (Linux/macOS):
You can automate the script to run at scheduled intervals by setting up a cron job. For example, to run it every day at midnight:
crontab -eAdd the following line:
0 0 * * * /usr/bin/php /path/to/db_backup_telegram.phpThe script logs all operations, including successful backups, errors, and Telegram uploads. By default, logs are written to backups/backup.log. You can change the log file location by modifying the log_file configuration.
The script supports automatic cleanup of old backups based on the retention_days configuration. For example, if set to 30, the script will delete backups older than 30 days. Set retention_days to 0 or leave it empty to disable retention.
This project is licensed under the MIT License.
© 2026 Seyyed Ali Mohammadiyeh (Max Base)
| Back | FazBrowse Home | New Git URL |