greathimansh / backup-auto-detect-database
Backup MySQL and MongoDB databases and upload to Google Drive automatically.
Requires
- php: ^8.1
- google/apiclient: ^2.18
- illuminate/support: ^9.0 || ^10.0 || ^11.0 || ^12.0
- spatie/db-dumper: ^3.8
README
Automatically backup MySQL or MongoDB databases and upload them to Google Drive, as a reusable Laravel package.
๐ Package by: greatHimanshu
๐ Features
- ๐ Secure upload to Google Drive using a Service Account
- ๐พ Auto-detect MySQL or MongoDB and perform dump
- โ๏ธ Upload
.sql
or.archive
file to Drive - ๐งน Auto-delete local files after upload
- ๐ Ready for Laravel scheduler integration
- ๐งฉ Easy to install and use
๐ฅ Installation
1. Require the package via Composer
composer require greathimansh/backup-auto-detect-database
โ๏ธ Laravel Usage
1. Publish config (optional)
php artisan vendor:publish --tag=backup-auto-detect-config
This will publish a config file: config/backup-auto-detect.php
2. Add Service Account JSON file
Place your Google Drive service account key file here:
storage/app/google/service-account.json
๐ Configuration (.env
)
Add these entries:
GOOGLE_DRIVE_FOLDER_ID=your_drive_folder_id_here # โ Required โ Google Drive folder ID DB_BACKUP_TYPE=mysql # โ Required โ mysql or mongodb MYSQLDUMP_PATH=your_mysql_dump_path_here # ๐ Optional โ full path if mysqldump is not in system PATH MONGODUMP_PATH=your_mongodb_dump_path_here # ๐ Optional โ full path if mongodump is not in system PATH BACKUP_REPLACE=true # ๐ Optional โ if true, will delete old backup before uploading new
โถ๏ธ Run the Command
Use the built-in Artisan command:
php artisan backup:auto-upload
Example output:
Starting database backup...
Detected: MySQL
Dumping all databases...
Uploading to Google Drive...
โ
Upload complete. Local file deleted.
๐ Automate with Laravel Scheduler
In app/Console/Kernel.php
:
$schedule->command('backup:auto-upload')->dailyAt('02:00');
Run scheduler every minute via cron (Linux):
* * * * * cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1
On Windows, use Task Scheduler.
๐งฉ Supported Versions
- PHP 8.1+
- Laravel 9, 10, 11, 12
- MySQL via
mysqldump
- MongoDB via
mongodump
Ensure mysqldump
or mongodump
is available in system PATH
or provide full path in the config.
๐ Where does it store backups?
- Files are uploaded to your Google Drive folder
- Filename format:
all-databases-backup.sql
or.archive
(MongoDB)
๐งโ๐ป Contributing
PRs are welcome. Make sure your code is clean, PSR-4 compliant, and properly documented.
๐จโ๐ Author
greatHimanshu
๐ GitHub
๐ก License
This package is licensed under the MIT License.