prodhan/laravel-backup-google-drive

Laravel Backup with Google Drive integration wrapper package

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/prodhan/laravel-backup-google-drive

v1.0.0 2025-12-02 22:43 UTC

This package is not auto-updated.

Last update: 2025-12-31 21:41:46 UTC


README

Latest Version on Packagist Total Downloads License

A Laravel package that provides seamless integration between Spatie Laravel Backup and Google Drive using masbug/flysystem-google-drive-ext.

Features

  • ✅ Easy Google Drive filesystem integration
  • ✅ Backup uploaded files to Google Drive
  • ✅ Debug tools for Google Drive connection
  • ✅ Automatic cleanup of old backup files
  • ✅ Works with Spatie Laravel Backup package
  • ✅ Support for folder IDs and folder names

Installation

You can install the package via Composer:

composer require prodhan/laravel-backup-google-drive

The package will automatically register its service provider and commands.

Alternative: Install from GitHub

If you prefer to install directly from GitHub:

composer require prodhan/laravel-backup-google-drive:dev-main

Or add to your composer.json:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/prodhan/laravel-backup-google-drive.git"
        }
    ],
    "require": {
        "prodhan/laravel-backup-google-drive": "dev-main"
    }
}

Configuration

1. Publish Configuration (Optional)

php artisan vendor:publish --tag=backup-google-drive-config

2. Configure Google Drive in config/filesystems.php

Add the Google Drive disk configuration:

'disks' => [
    // ... other disks
    
    'google' => [
        'driver' => 'google',
        'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
        'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
        'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
        'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'), // Recommended
        'folder' => env('GOOGLE_DRIVE_FOLDER'), // Alternative to folderId
    ],
],

3. Configure Spatie Backup in config/backup.php

Update the backup destination:

'destination' => [
    'disks' => [
        'google', // Add 'google' to your backup disks
    ],
],

'backup' => [
    'name' => env('BACKUP_NAME', ''), // Empty string to save directly in folder
    // ... other config
],

4. Set Environment Variables

Add to your .env file:

GOOGLE_DRIVE_CLIENT_ID=your-client-id
GOOGLE_DRIVE_CLIENT_SECRET=your-client-secret
GOOGLE_DRIVE_REFRESH_TOKEN=your-refresh-token
GOOGLE_DRIVE_FOLDER_ID=your-folder-id

Getting Google Drive Credentials

  1. Go to Google Cloud Console
  2. Create a new project or select existing one
  3. Enable Google Drive API
  4. Create OAuth 2.0 credentials (Desktop app)
  5. Use OAuth 2.0 Playground to get refresh token:

Getting Folder ID

  1. Open Google Drive in your browser
  2. Navigate to the folder you want to use
  3. The folder ID is in the URL: https://drive.google.com/drive/folders/FOLDER_ID_HERE
  4. Or use the debug command: php artisan google-drive:debug --list-folders

Usage

Backup Database (Spatie Backup)

php artisan backup:run --only-db

Backup Uploaded Files

# Backup public disk to Google Drive
php artisan backup:uploads

# Backup specific disk
php artisan backup:uploads --disk=local

# Backup specific folder
php artisan backup:uploads --path=products

# Custom filename
php artisan backup:uploads --filename=my-backup

# Different destination
php artisan backup:uploads --destination=s3

Debug Google Drive Connection

# Check credentials and connection
php artisan google-drive:debug

# List all folders
php artisan google-drive:debug --list-folders

# Find folder by name
php artisan google-drive:debug --folder-name=MyFolder

# Test write operation
php artisan google-drive:debug --test-write

Cleanup Old Backups

# Delete backups older than 7 days (default)
php artisan backup:clean-uploads

# Delete backups older than 14 days
php artisan backup:clean-uploads --days=14

# Clean specific disk
php artisan backup:clean-uploads --disk=google

# Custom prefix
php artisan backup:clean-uploads --prefix=my-backup-

Schedule Automatic Backups

Add to app/Console/Kernel.php:

protected function schedule(Schedule $schedule): void
{
    // Database backup daily at 1 AM
    $schedule->command('backup:run --only-db')->daily()->at('01:00');
    
    // Uploads backup daily at 2 AM
    $schedule->command('backup:uploads')->daily()->at('02:00');
    
    // Cleanup old backups daily at 3 AM
    $schedule->command('backup:clean')->daily()->at('03:00');
    $schedule->command('backup:clean-uploads --days=7')->daily()->at('03:00');
}

Available Commands

Command Description
backup:uploads Backup uploaded files to Google Drive
google-drive:debug Debug Google Drive connection
backup:clean-uploads Clean up old upload backup files

Requirements

  • PHP >= 8.1
  • Laravel >= 11.0
  • Spatie Laravel Backup >= 9.3
  • masbug/flysystem-google-drive-ext >= 2.4

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For issues and questions, please open an issue on GitHub.

License

The MIT License (MIT). Please see License File for more information.

Credits

Links