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
Requires
- php: ^8.1
- illuminate/console: ^11.0
- illuminate/filesystem: ^11.0
- illuminate/support: ^11.0
- masbug/flysystem-google-drive-ext: ^2.4
- spatie/laravel-backup: ^9.3
This package is not auto-updated.
Last update: 2025-12-31 21:41:46 UTC
README
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
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google Drive API
- Create OAuth 2.0 credentials (Desktop app)
- Use OAuth 2.0 Playground to get refresh token:
- Go to OAuth 2.0 Playground
- Select "Drive API v3"
- Authorize and get refresh token
Getting Folder ID
- Open Google Drive in your browser
- Navigate to the folder you want to use
- The folder ID is in the URL:
https://drive.google.com/drive/folders/FOLDER_ID_HERE - 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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.