PHP code example of mhmdomer / laravel-database-backup

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

    

mhmdomer / laravel-database-backup example snippets


return [

    /*
    |-------------------------------------------------------------------------
    | Backup Folder
    |-------------------------------------------------------------------------
    |
    | The path of the folder to save backups on and retrieve backups from.
    */

    'backup_folder' => storage_path('app/backup'),

    /*
    |-------------------------------------------------------------------------
    | Maximum Backup Files
    |-------------------------------------------------------------------------
    |
    | The maximum number of files that should be present inside the backup folder,
    | each new backup after this limit will result in removing the oldest backup file
    */

    'maximum_backup_files' => 10,

    /*
    |-------------------------------------------------------------------------
    | Mail Settings
    |-------------------------------------------------------------------------
    | Email configuration for backups.
    */

    "mail" => [

        /*
        |-------------------------------------------------------------------------
        | Send Mail
        |-------------------------------------------------------------------------
        | Specify if an email with the backup file attached should
        | be sent when creating a backup.
        */

        'send' => env('DB_BACKUP_SEND_MAIL', false),

        /*
        |-------------------------------------------------------------------------
        | Backup Mail
        |-------------------------------------------------------------------------
        | Specify the email that should receive the backup file.
        */

        'to' => env('DB_BACKUP_EMAIL', '[email protected]')
    ]
];


$schedule->command('database:backup')->daily();

DatabaseBackup::getLatestBackupFile();

DatabaseBackup::getBackupFiles();

$backupFile = DatabaseBackup::getLatestBackupFile();
return response()->download($backupFile);

protected $listen = [
    Mhmdomer\DatabaseBackup\Events\DatabaseBackupComplete::class => [
        SendSuccessMessage::class,
    ],
    Mhmdomer\DatabaseBackup\Events\DatabaseBackupFailed::class => [
        LogException::class,
    ],
];
bash
php artisan vendor:publish --tag=database-backup
bash
php artisan database:backup
bash
php artisan database:backup --no-mail