PHP code example of marekmiklusek / database-backup

1. Go to this page and download the library: Download marekmiklusek/database-backup 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/ */

    

marekmiklusek / database-backup example snippets


// config/database-backup.php
'storage' => [
    'disk' => 'local',              // 'local' or your Google Drive disk name
    'google_disk' => 'google',      // which filesystems disk holds the Drive credentials
    'use_both_disks' => false,      // keep a local copy and upload to Drive
    'directory' => 'database-backups',
    'filename' => [
        'prefix' => env('DB_DATABASE', 'laravel'),
        'date_format' => 'Y-m-d_H-i-s',
    ],
],

// config/database-backup.php
'cleanup' => [
   'automatic' => false,
],

'google' => [  // Can be renamed to your preferred disk name
    'driver' => 'google',
    'client_id' => env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'refresh_token' => env('GOOGLE_REFRESH_TOKEN'),
    'folder_id' => env('GOOGLE_FOLDER_ID'),
]

'storage' => [
    'google_disk' => 'google_db_backup',
],

// config/database-backup.php
'notifications' => [
    'mail' => [
        'to' => '[email protected]',
        'from' => [
            'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
            'name' => env('MAIL_FROM_NAME', 'Example'),
        ],
    ],

    'events' => [
        'backup_successful' => false,
        'backup_failed' => false,
        'cleanup_successful' => false,
        'cleanup_failed' => false,
    ],
],
bash
php artisan vendor:publish --tag=database-backup-config
bash
php artisan vendor:publish --tag=database-backup-config --force
php artisan config:clear
bash
php artisan db-backup:run
bash
php artisan db-backup:cleanup
bash
php artisan config:clear