PHP code example of salvatorecervone / backup-database

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

    

salvatorecervone / backup-database example snippets


'middleware' => ['web', 'auth', 'can:admin'],

'route_prefix' => 'backups',

// Optional: gate-based authorization (define the gate in your AuthServiceProvider)
'authorization_gate' => 'viewBackups',

'listconnections' => [
    [
        'connection' => 'sqlsrv', // Connection name in your database.php
        'daily' => true,
        'datetimeFormat' => 'Y-m-d_H-i',
        'destinationpath' => '//192.168.1.100/backups/', // Supports SMB shares or local paths
        'days_for_delete' => 7, // Keep backups for 7 days
        'soft_delete' => true, // Move to /trash instead of permanent deletion
    ],
],

'bin_paths' => [
    'sqlcmd' => '/opt/mssql-tools18/bin/sqlcmd',
    'mysqldump' => 'mysqldump',
    'mysql' => 'mysql',
    'smbclient' => 'smbclient',
],

'notification_email' => '[email protected]',

'enable_logging' => true,

use Illuminate\Support\Facades\Schedule;

Schedule::command('backup-database:backup')->dailyAt('03:00');

use SalvatoreCervone\BackupDatabase\Facades\BackupDatabase;

// Run backup for all connections
$results = BackupDatabase::backup();

// Get status/file list
$status = BackupDatabase::getStatus();

// Restore a specific backup (connection name + file basename)
$result = BackupDatabase::restore('sqlsrv', 'MyDB_2026-09-24.bak');

// Delete a backup file
$result = BackupDatabase::delete('sqlsrv', 'MyDB_old.bak');
bash
php artisan vendor:publish --tag="backup-database-config"
bash
php artisan backup-database:backup