PHP code example of smwks / laravel-db-snapshots

1. Go to this page and download the library: Download smwks/laravel-db-snapshots 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/ */

    

smwks / laravel-db-snapshots example snippets


'filesystem' => [
    'local_disk'   => 'local',
    'local_path'   => 'db-snapshots',
    'archive_disk' => 's3',        // any configured disk, or 'cloud' to use your default cloud disk
    'archive_path' => 'db-snapshots',
],

'plans' => [
    'daily' => [
        'connection'         => null,             // null = use default connection; driver auto-detected
        'file_template'      => 'db-snapshot-daily-{date:Ymd}',
        'dump_options'       => '--single-transaction --no-tablespaces',
        'schema_only_tables' => ['failed_jobs'],  // dump structure only, no data
        'tables'             => [],               // empty = all tables
        'ignore_tables'      => [],               // tables to skip entirely
        'keep_last'          => 1,                // number of snapshots to retain during cleanup
        'environment_locks'  => [
            'create' => 'production',             // only allow creation in this environment
            'load'   => 'local',                  // only allow loading in this environment
        ],
        'post_load_sqls' => [
            // SQL to run after loading this plan's snapshot
            // 'UPDATE users SET password = "$2y$10$..."',
        ],
    ],
],

// MySQL 8.0+
'dump_options' => '--single-transaction --no-tablespaces --set-gtid-purged=OFF --column-statistics=0',

// MariaDB
'dump_options' => '--single-transaction --no-tablespaces',

// PostgreSQL
'dump_options' => '--no-owner --no-acl',

'plan_groups' => [
    'all-daily' => [
        'plans' => ['daily-main', 'daily-analytics'],
        'post_load_sqls' => [
            // SQL to run after ALL plans in the group have loaded
            'ANALYZE TABLE users',
        ],
    ],
],

'cache_by_default' => false,  // set to true to enable smart caching globally

'utilities' => [
    'mysql' => [
        'mysqldump' => 'mysqldump',  // or '/usr/local/bin/mysqldump'
        'mysql'     => 'mysql',
    ],
    'pgsql' => [
        'pg_dump' => 'pg_dump',
        'psql'    => 'psql',
    ],
    'zcat' => 'zcat',
    'gzip' => 'gzip',
],

// Global
'post_load_sqls' => [
    'SET GLOBAL time_zone = "+00:00"',
],

// Inside a plan
'plans' => [
    'daily' => [
        'post_load_sqls' => [
            'UPDATE users SET email = CONCAT("user", id, "@example.com")',
        ],
    ],
],
bash
php artisan vendor:publish --provider="SMWks\LaravelDbSnapshots\DbSnapshotsServiceProvider" --tag="config"