ratulsaqibkhan/laravel-backup-google-drive

Backup Laravel Application using laravel backup in google drive

v1.0.0 2022-05-14 11:34 UTC

This package is auto-updated.

Last update: 2024-04-22 06:56:31 UTC


README

This is a laravel package to backup your application in google drive along with local directory. This package is inspired by Spatie Laravel Backup and Flysystem Adapter for Google Drive

Install this package using the following command

composer require ratulsaqibkhan/laravel-backup-google-drive
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
  • Next step is to add google and backup in the disk option in the config/backup.php.
'disks' => [
    'google',
    'backup',
],
  • Now set up empty string to the name option in the config/backup.php.
/*
* The name of this application. You can use this name to monitor
* the backups.
*/
'name' => '',
  • Afterward, register GoogleDriveServiceProvider provider inside the config/app.php file.
'providers' => [
    Ratulsaqibkhan\LaravelBackupGoogleDrive\Providers\GoogleDriveServiceProvider::class,
]
  • At this point, we will add the storage disk configuration to config/filesystem.php:
return [
  
    // ...
    
    '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'),
        ],
        
        'backup' => [
            'driver' => 'local',
            'root' => base_path('backup'),
        ],
        // ...
        
    ],
    
    // ...
];
  • Now create a folder named "backup" in the application root at which the local backup files could be kept

  • Next, we need to update .env file. In this environment file we need to add the following Google credentials with BACKUP_ENABLE:

BACKUP_ENABLE = true

GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER_ID=null
  • Now, add backup_enable in config/backup.php outside of backup configuration
    'backup_enable' => env('BACKUP_ENABLE', false),
    'backup' = [
      ...
    ]
  • With the following command the application can be backup:
php artisan laravel-app:backup