PHP code example of prodhan / laravel-backup-google-drive

1. Go to this page and download the library: Download prodhan/laravel-backup-google-drive library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

prodhan / laravel-backup-google-drive example snippets


'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
    ],
],

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

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

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');
}
bash
php artisan vendor:publish --tag=backup-google-drive-config
bash
php artisan backup:run --only-db
bash
# 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
bash
# 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-