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