greathimansh/backup-auto-detect-database

Backup MySQL and MongoDB databases and upload to Google Drive automatically.

v1.0.5 2025-06-08 10:52 UTC

This package is auto-updated.

Last update: 2025-09-08 11:36:27 UTC


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.