A simple Laravel package to automatically backup your database and storage directory, with a Blade-based UI to view, download, and delete backups.
- 🔄 Daily backup of database and storage (storage/app/public)
- 🧼 Auto-delete backups older than configurable days (default 5 days)
- 🧾 List, download, and delete backups via Blade UI
- 👤 Access control using roles and middleware
- 🛠 Configurable via config/laravelBackup.php
Install the package via composer:
composer require avcodewizard/laravel-backupEdit the config file at: config/laravelBackup.php
return [
    'backup_path' => storage_path('backups'),
    'keep_days' => 5, // Automatically delete backups older than 5 days
    'backup_storage_directory' => false, // true or false 
    'check_access' => false, // Enable/disable role-based access to UI
    'allowed_roles' => [], // Role Names Example: ['Admin', 'Super-Admin','Developer', 'Manager']
];- If you want's to backup storage directory
'backup_storage_directory' => true, // true or false 
To enable UI access control based on user roles:
- Set 'check_access' => true
- Add roles in 'allowed_roles' => ['Admin']
- Ensure your Usermodel has ahasRole()method (e.g., using spatie/laravel-permission)
Middleware used:
Avcodewizard\LaravelBackup\Http\Middleware\CheckLaravelBackupAccess
Access the UI at:
/laravel-backup
Example route setup (already included in the package):
Route::prefix('laravel-backup')
    ->middleware(['web', \Avcodewizard\LaravelBackup\Http\Middleware\CheckLaravelBackupAccess::class])
    ->group(function () {
        Route::get('/', [BackupController::class, 'index'])->name('laravel-backup.index');
        Route::get('/create', [BackupController::class, 'create'])->name('laravel-backup.create');
        Route::get('/download', [BackupController::class, 'download'])->name('laravel-backup.download');
        Route::delete('/delete', [BackupController::class, 'delete'])->name('laravel-backup.delete');
    });- Go to /laravel-backup
- Click Create Backup
- If use want to create backup from ui, make sure to run the queue worker:
php artisan queue:workphp artisan backup:runBackups older than keep_days will be deleted automatically.
In app/Console/Kernel.php, add:
$schedule->command('backup:run')->daily();Backups are saved in:
storage/backups/
Each backup includes:
- YYYY-MM-DD-HH-MM-SS_database.sql
- YYYY-MM-DD-HH-MM-SS_storage.zip
php artisan vendor:publish --tag=laravel-backupThis will publish:
- config/laravelBackup.php
- Blade views to resources/views/vendor/laravel-backup/
The package uses a configurable middleware to restrict access:
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);You can customize access logic using roles or your own permission methods.
This package is open-sourced software licensed under the MIT license.
© 2025 Avcodewizard