Search by

doss / laravel-db-backup

dossmedaziz

Back up your Laravel database to Google Drive with `php artisan db:backup`.

Package info

github.com/dossmedaziz/laravel-db-backup

pkg:composer/doss/laravel-db-backup

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-11-03 16:51 UTC

This package is auto-updated.

Last update: 2026-11-04 09:28:42 UTC


README

Back up your Laravel database to Google Drive:

php artisan db:backup

What it does:

  1. Dumps the database into a temporary folder: storage/app/db-backups/classquiz_2026-10-05-02-00/classquiz_2026-10-05-02-00.dump
  2. Zips that folder: storage/app/db-backups/classquiz_2026-10-05-02-00.zip
  3. Uploads the zip to your Google Drive folder
  4. Deletes the local zip once the upload has succeeded

Supported databases: PostgreSQL (pg_dump), MySQL / MariaDB (mysqldump), SQLite. Connection details come from your existing config/database.php.

Installation

composer require doss/laravel-db-backup

The service provider is auto-discovered.

Configuration

Two settings are needed, in .env:

DB_BACKUP_GOOGLE_FOLDER_ID=your-folder-id          # from https://drive.google.com/drive/folders/<FOLDER_ID>
DB_BACKUP_GOOGLE_CREDENTIALS=client_secret.json     # OAuth client secret or service account key

Relative paths are resolved from the project root. If DB_BACKUP_GOOGLE_CREDENTIALS is not set, the file is read from storage/app/google/credentials.json. The package detects which kind of JSON file it is.

To change the dump path, name prefix, date format, timeout or pg_dump / mysqldump binaries, publish the config:

php artisan vendor:publish --tag=db-backup-config

Google Drive setup

In Google Cloud Console, enable the Google Drive API, then pick one of the following.

OAuth client secret (personal Google account, recommended)

  1. Create an OAuth client of type Desktop app and download its JSON (client_secret.json).

  2. Set DB_BACKUP_GOOGLE_CREDENTIALS to that file.

  3. Run once:

    php artisan db-backup:google-auth

    Open the link, allow access, and paste the code (or the full redirect URL). The token is saved to storage/app/google/token.json (DB_BACKUP_GOOGLE_TOKEN) and refreshed automatically after that.

Service account (Google Workspace Shared Drive)

  1. Create a service account and download its JSON key.
  2. Set DB_BACKUP_GOOGLE_CREDENTIALS to that file.
  3. Add the service account e-mail (...@...iam.gserviceaccount.com) to the Shared Drive as Content manager.

Service accounts have no storage quota of their own, so they cannot upload to a personal "My Drive" folder (storageQuotaExceeded). Use OAuth for a personal account.

Keep the credentials and token files out of git.

Usage

php artisan db:backup                     # dump, zip, upload, delete the local zip
php artisan db:backup --keep-local        # same, but keep the local zip
php artisan db:backup --no-upload         # only create the local zip
php artisan db:backup --connection=mysql  # back up another connection

If the upload fails, the error is logged, the command exits with a non-zero code, and the local zip is kept.

Scheduling

In routes/console.php (Laravel 11+):

use Illuminate\Support\Facades\Schedule;

Schedule::command('db:backup')->dailyAt('02:00')->withoutOverlapping();

or in app/Console/Kernel.php (Laravel 10):

$schedule->command('db:backup')->dailyAt('02:00')->withoutOverlapping();

Make sure the Laravel scheduler cron is running:

* * * * * cd /path/to/app && php artisan schedule:run >> /dev/null 2>&1

Requirements

  • PHP 8.1+ with the zip extension, Laravel 10–13
  • pg_dump or mysqldump installed on the server (matching your DB server version)

License

MIT