A free, open-source tool to back up MySQL databases from cPanel (or a LAMP server) to local storage, Google Drive, or Telegram. Supports four modes: local storage, zip upload to Google Drive, direct streaming to Google Drive, or zip upload to Telegram. Multiple modes can be used simultaneously for flexible backups. Designed to be easy to use, maintain, and debug, with efficient multi-mode execution and detailed logging.
config.php):
local: Save backups to the server.gd-upload: Save backups locally, zip them, and upload the zip file to Google Drive.gd-stream: Stream backups directly to Google Drive without local storage.tg-upload: Save backups locally, zip them, and upload the zip file to a Telegram chat..refresh-token.php for security.gd-upload and tg-upload to minimize disk I/O).local mode is used.curl, pdo_mysql, openssl, zlib, and zip extensions (checked at runtime).chmod 755 /path/to/gdbackup).gd-upload or gd-stream modes):
tg-upload mode):
git clone https://github.com/dominusmmp/gdbackup.git/home/username/gdbackup).chmod 755 /path/to/gdbackup.config.php, .refresh-token.php, error.*.log) by placing them outside the web root or using .htaccess:
<FilesMatch "^(config\.php|\.refresh-token\.php|error.*\.log)$">
Deny from all
</FilesMatch>
src directory.The project includes a template configuration file, config.template.php, which you should copy and rename to config.php before customizing. Do not edit config.template.php directly, as it serves as a reference for the required settings. For Google Drive API authentication (for gd-upload or gd-stream modes), use auth.html to obtain the authorization code.
config.php:
config.template.php to config.php:
cp config.template.php config.php
config.php in a text editor and fill in the required values as described below.config.php is protected (e.g., chmod 600 config.php) and placed outside the web root or secured via .htaccess.config.php are correctly filled to avoid runtime errors.$isProductionMode (config.php):
true for production (logs errors to error.Y-m-d.log).false for debugging (displays errors in the cli/browser).$cronjobKey (config.php):
'x7k9p2m4q8v5n3j6h'.$root (config.php):
__DIR__).chmod 755 /path/to/gdbackup).$backupFilesPrefix (config.php):
prefix.20250101.sql.gz).$mode (config.php):
['local'], ['gd-upload', 'tg-upload'], etc.'local', 'gd-upload', 'gd-stream', 'tg-upload'.['local', 'gd-upload', 'tg-upload'] backs up to local disk, Google Drive, and Telegram.$timezone (config.php):
'UTC', 'America/New_York').$retentionDays (config.php):
30).0 for unlimited retention.tg-upload, manual cleanup is required due to Telegram API limitations.$memoryLimit (config.php):
'512M', '1024M').512M for small databases, 2048M for large ones).512M, 1G); invalid formats may cause errors.$dbHost (config.php):
'localhost:3306' or 'db.example.com').$dbUsername (config.php):
'myuser').$dbPassword (config.php):
'mypassword').$dbNames (config.php):
['mydatabase']).AUTO_INCREMENT, ENGINE, CHARSET, COLLATE are removed) for simpler backups. Verify compatibility during restoration.gd-upload or gd-stream modes)http://yourdomain.com/auth.html or https://dominusmmp.github.io/gdbackup/auth.html) under “Authorized redirect URIs”.$authCode:
auth.html to generate the authorization code:
auth.html on your local web server (e.g., http://localhost/auth.html).auth.html to your web server (e.g., http://yourdomain.com/auth.html).https://dominusmmp.github.io/gdbackup/auth.html.auth.html with your authCode displayed.authCode and paste it into $authCode in config.php.
$authCode = '4/0A...';
config.php:
$driveRootFolderId:
https://drive.google.com/drive/folders/YourFolderID.'1aBcDeFgHiJkLmNoPqRsTuVwXyZ'.$clientId:
'1234567890-abcdefg.apps.googleusercontent.com').$clientSecret:
'GOCSPX-abcdefg1234567890').$redirectUri:
auth.html (e.g., http://yourdomain.com/auth.html or https://dominusmmp.github.io/gdbackup/auth.html).$authCode:
'4/0A...').$encryptionPassword:
'StrongPassword123!').$encryptionKey:
'550e8400-e29b-41d4-a716-446655440000'..refresh-token.php with the format <?php defined('GDBPATH') || die('forbidden'); // [timestamp] $encryptedToken. Protect this file (chmod 600) and back it up. If lost or corrupted, regenerate $authCode via auth.html.tg-upload mode)/newbot, follow the prompts to name your bot, and receive a Bot API token (e.g., 123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11).config.php.123456789).-123456789 or -100123456789).@MyBackupChannel) or a negative integer (e.g., -100123456789).@MyBackupChannel).https://api.telegram.org/bot<YourBotToken>/getUpdates.chat object in the response to find the id or username.config.php:
$telegramBotToken:
'123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11').$telegramChatId:
'123456789').'-123456789' or '-100123456789').'@MyBackupChannel') or negative integer (e.g., '-100123456789').$telegramFileSizeLimit:
50000000 for 50MB).2000000000 (2GB).2000000000.Example configuration in config.php:
$telegramBotToken = '123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11';
$telegramChatId = '@MyBackupChannel'; // Or '123456789' for private chat, '-100123456789' for group/channel
$telegramFileSizeLimit = 50000000;
http://yourdomain.com/run.php?key=your-cronjob-keyphp /path/to/run.php your-cronjob-key/usr/local/bin/php /path/to/run.php your-cronjob-key
$root/prefix/ as zipped files (e.g., prefix.20250101.zip).local mode is used.error.Y-m-d.log in the .logs directory for issues.The restore.php script restores a MySQL database from a .sql or .sql.gz backup file created by run.php. It supports both hardcoded configuration and interactive CLI prompts.
restore.php (optional):
restore.php and set the following variables at the top:
$dbHost = 'localhost:3306'; // Database host
$dbUsername = 'myuser'; // Database username
$dbPassword = 'mypassword'; // Database password
$dbName = 'mydatabase'; // Database to restore
$backupFile = '/path/to/backup.sql.gz'; // Path to .sql or .sql.gz file
php /path/to/restore.php
dbHost, dbUsername, dbPassword, dbName, and backupFile.http://yourdomain.com/restore.php (requires variables to be set in the script)..sql.gz) are automatically deleted..sql or .sql.gz file generated by this project.chmod 644 or higher)./usr/local/bin/php).$root is within your home directory (e.g., /home/username/gdbackup).chmod 755 for the script directory and chmod 600 for config.php, .refresh-token.php, and ./logs/*.$memoryLimit (e.g., 2048M) for large databases to avoid memory errors.$cronjobKey matches in config.php and your cronjob/URL.config.php are filled, especially for selected modes (e.g., Google Drive or Telegram configs).$mode in config.php contains only valid modes (local, gd-upload, gd-stream, tg-upload).curl, pdo_mysql, openssl, zlib, or zip extension is not loaded”
$clientId, $clientSecret, and $redirectUri in config.php.$redirectUri in config.php..refresh-token.php is corrupted or deleted, regenerate $authCode via auth.html.auth.html.$telegramBotToken and $telegramChatId in config.php.$telegramFileSizeLimit (default 50MB, 2GB for premium bots).chmod 755).config.php, .refresh-token.php, and ./logs/* (chmod 600).$memoryLimit in config.php (e.g., 2048M) for large databases.$isProductionMode = false to display errors..logs/error.Y-m-d.log for detailed logs, including timestamps and error levels.auth.html issues, open the browser console (F12) to view JavaScript errors.🗂️ gdbackup/
├── 📁 .logs/
│ └── error.Y-m-d.log
├── 📁 src/
│ ├── BackupController.php
│ ├── EncryptionHelper.php
│ ├── GoogleDriveAPI.php
│ ├── Logger.php
│ ├── MySQLBackupAPI.php
│ ├── TelegramAPI.php
│ └── ZipHelper.php
├── .gitignore
├── .htaccess
├── .refresh-token.php
├── auth.html
├── config.php
├── config.template.php
├── readme.md
├── restore.php
└── run.php
Licensed under the MIT License. See LICENSE for details.