PHP code example of nyoncode / laravel-backup-manager

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

    

nyoncode / laravel-backup-manager example snippets


'profiles' => [
    'default' => [
        'name' => env('APP_NAME', 'Laravel'),
        'type' => 'full',                       // full | database | files
        'databases' => ['connections' => []],   // [] = default connection
        'files' => [
            '

'databases' => [
    'connections' => ['mysql', 'reporting'], // [] = the default connection
    'exclude_tables' => ['telescope_entries'],
    'schema_only_tables' => ['sessions', 'cache'], // structure kept, rows skipped
],

'files' => [
    '[base_path('vendor'), '*.log'],
    'follow_symlinks' => false, // record link metadata instead of following
    '

'compression' => ['algorithm' => 'gzip', 'level' => 6],

'encryption' => [
    'algorithm' => 'aes-256-gcm', // none | aes-256-cbc | aes-256-gcm
    'key' => env('BACKUP_ENCRYPTION_KEY'), // 32 bytes, base64: accepted
],
'integrity' => [
    'checksum' => 'sha256',
    'signing' => ['enabled' => true, 'key' => env('BACKUP_SIGNING_KEY')],
],

'destinations' => ['s3', 'local'],

'retention' => [
    'strategy' => 'gfs',
    'gfs' => ['keep_daily' => 7, 'keep_weekly' => 4, 'keep_monthly' => 6, 'keep_yearly' => 2],
    'max_age_days' => 365,
    'max_storage_megabytes' => null,
],

'schedule' => ['enabled' => true, 'backup' => '0 2 * * *', 'cleanup' => '0 4 * * *', 'monitor' => '0 6 * * *'],
'queue' => ['enabled' => true, 'queue' => 'backups', 'timeout' => 3600],

'monitoring' => [
    'max_backup_age_hours' => 25,
    'store_history' => true,
    'notifications' => [
        'enabled' => true,
        'on' => ['failure', 'unhealthy'],
        'mail' => ['to' => ['[email protected]']],
        'slack' => ['webhook_url' => env('BACKUP_NOTIFY_SLACK')],
    ],
],

use Nyoncode\BackupManager\Facades\Backup;
use Nyoncode\BackupManager\Contracts\Storage\BackupRepository;
use Nyoncode\BackupManager\Managers\RestoreManager;
use Nyoncode\BackupManager\DTOs\RestoreOptions;

// Create
$result = Backup::run();                 // or Backup::run('nightly')
$result->archiveFileName;                // nightly-2026-07-16-020000-a1b2c3.tar.gz.enc
$result->manifest->fileCount();

// Restore
$backup = app(BackupRepository::class)->list('s3', 'backups')[0]; // newest
app(RestoreManager::class)->restore($backup, RestoreOptions::databasesOnly());
bash
php artisan vendor:publish --tag="backup-manager-config"
bash
php artisan vendor:publish --tag="backup-manager-migrations"
php artisan migrate
bash
php artisan backup:restore                    # newest, everything
php artisan backup:restore --database         # databases only
php artisan backup:restore --files            # files only
php artisan backup:restore --only=/var/www/app/config   # selected directories
bash
php artisan backup:clean --dry-run   # preview
bash
php artisan backup:mcp
bash
claude mcp add backup-manager -- php artisan backup:mcp
bash
php artisan backup:upgrade <licence-key>