PHP code example of xslain / database-backup-sync

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

    

xslain / database-backup-sync example snippets


use DatabaseBackupSync\Facades\DatabaseBackup;

// Run a backup to the default driver(s)
$result = DatabaseBackup::backup(['label' => 'pre-deploy']);

// Backup to specific drivers, encrypted
$result = DatabaseBackup::backup([
    'drivers' => ['s3', 'google_drive'],
    'encrypt' => true,
    'label'   => 'nightly',
]);

// Apply retention pruning
DatabaseBackup::prune();

// List backups
$backups = DatabaseBackup::listBackups('s3');

// Restore a backup
DatabaseBackup::restore('backup_2026-08-16_02-00-00.sql.gz.enc', [
    'driver'     => 's3',
    'connection' => 'mysql',
    'decrypt'    => true,
]);

// Test driver connectivity
DatabaseBackup::testDrivers();
bash
php artisan vendor:publish --tag=database-backup-config
php artisan vendor:publish --tag=database-backup-migrations
php artisan migrate
bash
php -r "echo base64_encode(random_bytes(32));"