prodhan/laravel-backup-google-drive
Composer 安装命令:
composer require prodhan/laravel-backup-google-drive
包简介
Laravel Backup with Google Drive integration wrapper package
README 文档
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.
Credits
Links
prodhan/laravel-backup-google-drive 适用场景与选型建议
prodhan/laravel-backup-google-drive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「backup」 「laravel」 「Flysystem」 「spatie」 「google-drive」 「cloud-storage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 prodhan/laravel-backup-google-drive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 prodhan/laravel-backup-google-drive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 prodhan/laravel-backup-google-drive 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Backblaze B2 Cloud Storage for Laravel 5. Original by Paul Olthof (@hpolthof) continued by @bringyourownideas
Virtual Filesystem Storage Adapter for Laravel
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
Adds Silverstripe Flysystem support for using the Azure Blob adapter
Flysystem adapter for OneDrive or SharePoint
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-02