PHP code example of phattarachai / db-snapshot-sync-laravel
1. Go to this page and download the library: Download phattarachai/db-snapshot-sync-laravel 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/ */
phattarachai / db-snapshot-sync-laravel example snippets
// config/db-snapshot-sync.php
'backup' => [
'disks' => ['spaces'], // any disks from config/filesystems.php, one or more
'path' => 'db', // prefix on each target; let the disk's root carry the app/env
'local_days' => 14, // snapshot:prune deletes local snapshots older than this
'keep_min' => 3, // ...but never below the newest 3 (local, and each target's daily/)
'daily_days' => 14, // {path}/daily/ keeps every snapshot this many days
'weekly_weeks' => 8, // {path}/weekly/ keeps the newest snapshot of each ISO week
'stale_after_hours' => 26, // snapshot:backup-check threshold
'protect' => ['testing'], // snapshot names never pruned and never uploaded
'queue' => env('DB_SNAPSHOT_SYNC_BACKUP_QUEUE'),
],
use Google\Client;
use Google\Service\Drive;
use Illuminate\Filesystem\FilesystemAdapter;
use League\Flysystem\Filesystem;
use Masbug\Flysystem\GoogleDriveAdapter;
Storage::extend('google-drive', function ($app, array $config): FilesystemAdapter {
$client = new Client;
$client->setAuthConfig($config['service_account']); // path to the key JSON, or its decoded array
$client->addScope(Drive::DRIVE);
$adapter = new GoogleDriveAdapter(new Drive($client), $config['root'] ?? null, [
'teamDriveId' => $config['shared_drive_id'],
]);
return new FilesystemAdapter(new Filesystem($adapter, $config), $adapter, $config);
});
'gdrive' => [
'driver' => 'google-drive',
'service_account' => env('GOOGLE_DRIVE_SERVICE_ACCOUNT'), // e.g. /etc/myapp/gdrive-sa.json
'shared_drive_id' => env('GOOGLE_DRIVE_SHARED_DRIVE_ID'),
'root' => env('GOOGLE_DRIVE_ROOT'), // e.g. myapp, a folder in the Shared Drive
'throw' => true,
],