1. Go to this page and download the library: Download avcodewizard/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/ */
avcodewizard / laravel-backup example snippets
return [
'destinations' => [
'local' => [
'enabled' => true,
'path' => storage_path('backups'),
],
's3' => [
'enabled' => false,
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'bucket' => env('AWS_BUCKET'),
'endpoint' => env('AWS_ENDPOINT'), // Optional: for MinIO, DO Spaces
'path' => 'backups',
],
'google_drive' => [
'enabled' => false,
// OAuth 2.0 credentials - get refresh token using: php artisan backup:google-auth
'client_id' => env('GOOGLE_DRIVE_CLIENT_ID'),
'client_secret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
'refresh_token' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
'folder_id' => env('GOOGLE_DRIVE_FOLDER_ID'), // Optional: specific folder ID
'path' => 'backups',
],
],
'keep_days' => 5, // Automatically delete backups older than 5 days
'cleanup_scope' => 'all', // 'all' = clean cloud + local, 'local' = clean local only
'backup_storage_directory' => false, // true or false - storage backup only if s3 or google_drive enabled
'check_access' => false, // Enable/disable role-based access to UI
'allowed_roles' => [], // Role Names Example: ['Admin', 'Super-Admin','Developer', 'Manager']
];
use Illuminate\Support\Facades\Schedule;
Schedule::call(function () {
Artisan::call('backup:run');
})->name('backup:run')->withoutOverlapping()->daily();
$schedule->command('backup:run')->daily();
if (!config('laravelBackup.check_access')) return $next($request);
$user = Auth::user();
if (!$user) {
abort(403, 'Unauthorized - no user authenticated.');
}
if (!method_exists($user, 'hasRole')) {
abort(403, 'User Role Not Implemented!');
}
if (!$user->hasAnyRole(config('laravelBackup.allowed_roles'))) {
abort(403, 'Unauthorized - insufficient permission.');
}
return $next($request);