PHP code example of redaelfillali / laravel-backup

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

    

redaelfillali / laravel-backup example snippets


use Redaelfillali\LaravelBackup\Backup;

class BackupController extends Controller
{
    public function runBackup()
    {
        $backupService = new BackupService();

        // Trigger a full backup
        $backupService->runBackup();

        // Or trigger specific types of backups
        // $backupService->runBackup(['only_db' => true]); // Backup only database
        // $backupService->runBackup(['only_files' => true]); // Backup only files
    }
}

use Illuminate\Console\Scheduling\Schedule;

protected function schedule(Schedule $schedule)
{
    $schedule->command('backup:run')
             ->daily(); // Run the backup daily
}

namespace App\Http\Controllers;

use Redaelfillali\LaravelBackup\BackupService;
use Illuminate\Http\Request;

class BackupController extends Controller
{
    public function createBackup()
    {
        $backupService = new BackupService();
        $backupService->runBackup();

        return response()->json(['message' => 'Backup completed successfully']);
    }
}

Route::get('/backup', [BackupController::class, 'createBackup']);

bash
php artisan vendor:publish --provider="Redaelfillali\LaravelBackup\BackupServiceProvider"
bash
php artisan backup:run