PHPackages                             avcodewizard/laravel-backup - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. avcodewizard/laravel-backup

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

avcodewizard/laravel-backup
===========================

A Laravel package for database and storage backup with auto-cleanup.

2.0.0(2mo ago)2341MITPHPPHP &gt;=8.0

Since Apr 14Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/avcodewizard/laravel-backup)[ Packagist](https://packagist.org/packages/avcodewizard/laravel-backup)[ RSS](/packages/avcodewizard-laravel-backup/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

📦 Laravel Backup Package
========================

[](#-laravel-backup-package)

[![Total Downloads](https://camo.githubusercontent.com/aedb3a1c0fc6d37bebe942087339cfea0d605e5c93e2d694cbe4e83ca05ea786/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6176636f646577697a6172642f6c61726176656c2d6261636b7570)](https://packagist.org/packages/avcodewizard/laravel-backup)[![Latest Stable Version](https://camo.githubusercontent.com/7075993ac9c1e53cbdca58ea30c84ae718c34b7a7badcc21c95b00ccc4f308cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6176636f646577697a6172642f6c61726176656c2d6261636b7570)](https://packagist.org/packages/avcodewizard/laravel-backup)[![License](https://camo.githubusercontent.com/878da003a15654d7cbd0a6f34fd9ce38f656ce650365f232a7df4578b6ea4039/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6176636f646577697a6172642f6c61726176656c2d6261636b7570)](https://packagist.org/packages/avcodewizard/laravel-backup)

A simple Laravel package to automatically **backup your database and storage directory** to multiple destinations (Local, Amazon S3, Google Drive), with a Blade-based UI to view, download, and delete backups.

---

🚀 Features
----------

[](#-features)

- 🔄 Daily backup of database and storage (`storage/app/public`)
- ☁️ **Multi-destination support**: Local, Amazon S3, Google Drive
- 🧼 Auto-delete backups older than configurable days (default 5 days)
- 🎯 Configurable cleanup scope: clean all destinations or local only
- 🧾 List, download, and delete backups from all destinations via Blade UI
- 👤 Access control using roles and middleware
- 🛠 Configurable via `config/laravelBackup.php`

---

📥 Installation
--------------

[](#-installation)

Install the package via composer:

```
composer require avcodewizard/laravel-backup
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Edit the config file at: `config/laravelBackup.php`

```
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']
];
```

### Backup Destinations

[](#backup-destinations)

Enable one or more destinations:

- **Local**: Saves backups to local disk (`storage/backups/` by default)
- **S3**: Uploads backups to Amazon S3 (or compatible services like DigitalOcean Spaces, MinIO)
- **Google Drive**: Uploads backups to Google Drive

When multiple destinations are enabled, backups are saved to **all enabled destinations** simultaneously.

### Cleanup Scope

[](#cleanup-scope)

- `'all'`: Delete old backups from **all destinations** (local + cloud)
- `'local'`: Delete old backups from **local storage only** (cloud backups kept indefinitely)

### Storage Directory Backup

[](#storage-directory-backup)

- When `backup_storage_directory` is `true` AND S3/Google Drive is enabled: Storage is backed up to **cloud only** (skips local to save disk space)
- When only local storage is enabled: Storage backup is skipped even if `backup_storage_directory` is true

---

🛡️ Access Control
-----------------

[](#️-access-control)

To enable UI access control based on user roles:

1. Set `'check_access' => true`
2. Add roles in `'allowed_roles' => ['Admin']`
3. Ensure your `User` model has a `hasRole()` method (e.g., using [spatie/laravel-permission](https://github.com/spatie/laravel-permission))

Middleware used:
`Avcodewizard\LaravelBackup\Http\Middleware\CheckLaravelBackupAccess`

---

🖥️ Web Interface
----------------

[](#️-web-interface)

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');
    });
```

---

🛠 Usage
-------

[](#-usage)

### Create Backup via Web

[](#create-backup-via-web)

1. Go to `/laravel-backup`
2. Click **Create Backup**

- If use want to create backup from ui, make sure to run the queue worker:

```
php artisan queue:work
```

### Create Backup via Terminal

[](#create-backup-via-terminal)

```
php artisan backup:run
```

---

🧹 Automatic Cleanup
-------------------

[](#-automatic-cleanup)

Backups older than `keep_days` will be deleted automatically.

### Add to Scheduler

[](#add-to-scheduler)

**Laravel 11+** (routes/console.php):

```
use Illuminate\Support\Facades\Schedule;

Schedule::call(function () {
    Artisan::call('backup:run');
})->name('backup:run')->withoutOverlapping()->daily();
```

**Laravel 10 and below** (app/Console/Kernel.php):

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

---

📂 Backup Storage
----------------

[](#-backup-storage)

Backups are saved to all **enabled destinations**:

### Local Storage

[](#local-storage)

```
storage/backups/

```

### Cloud Storage (S3, Google Drive)

[](#cloud-storage-s3-google-drive)

Backups are stored in the configured path (default: `backups/` folder)

### File Naming

[](#file-naming)

Each backup includes:

- `YYYY-MM-DD-HH-MM-SS_database.sql.gz` - Database backup
- `YYYY-MM-DD-HH-MM-SS_storage.zip` - Storage backup (cloud only)

---

🧑‍💻 Developer Notes
-------------------

[](#‍-developer-notes)

### Publish Config &amp; Views

[](#publish-config--views)

```
php artisan vendor:publish --tag=laravel-backup
```

This will publish:

- `config/laravelBackup.php`
- Blade views to `resources/views/vendor/laravel-backup/`

### Middleware Logic

[](#middleware-logic)

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.

---

☁️ Cloud Storage Setup
----------------------

[](#️-cloud-storage-setup)

### Amazon S3 / DigitalOcean Spaces / MinIO

[](#amazon-s3--digitalocean-spaces--minio)

1. Install AWS SDK

```
composer require aws/aws-sdk-php
```

2. Add AWS Credentials to `.env`

```
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=your-backup-bucket
# AWS_ENDPOINT=https://s3.custom-endpoint.com  # Optional: for MinIO, DO Spaces
```

3. Enable S3 in `config/laravelBackup.php`

```
'destinations' => [
    's3' => [
        'enabled' => true,
        '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', // Folder in your bucket
    ],
],
```

### Google Drive

[](#google-drive)

#### OAuth 2.0

[](#oauth-20)

Uses YOUR Google Drive storage for backups. Generate a refresh token to authenticate.

1. Install Google API Client

```
composer require google/apiclient
```

2. Create OAuth Credentials
3. Go to [Google Cloud Console](https://console.cloud.google.com/)
4. Create a new project or select existing
5. Enable **Google Drive API**
6. Go to **APIs &amp; Services** → **Credentials** → **Create Credentials** → **OAuth client ID**
7. Application type: **Web application**
8. Authorized redirect URIs: `http://localhost`
9. Copy your **Client ID** and **Client Secret**
10. Add Test User (Required for Unverified Apps)
11. In Google Cloud Console, go to **APIs &amp; Services** → **OAuth consent screen** (left sidebar)
12. Make sure Publishing Status is **"Testing"**
13. Go to **Audience** section
14. Under **Test users**, click **Add Users**
15. Add your Google email address
16. Click **Save**
17. Generate Refresh Token

**Option A: Using credentials from config (if already set)**

```
php artisan backup:google-auth
```

**Option B: Passing credentials directly**

```
php artisan backup:google-auth --client-id=YOUR_CLIENT_ID --client-secret=YOUR_CLIENT_SECRET
```

Follow the prompts to authorize and get your refresh token.

5. Add to `.env`

```
GOOGLE_DRIVE_CLIENT_ID=your-client-id
GOOGLE_DRIVE_CLIENT_SECRET=your-client-secret
GOOGLE_DRIVE_REFRESH_TOKEN=your-refresh-token
GOOGLE_DRIVE_FOLDER_ID=your-folder-id  # Optional
```

6. Enable in config

```
'destinations' => [
    'google_drive' => [
        'enabled' => true,
        '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'),
        'path' => 'backups',
    ],
],
```

**Note:** If your refresh token becomes invalid (user revoked access), regenerate it:

```
php artisan backup:google-auth
```

---

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

© 2025 [Avcodewizard](https://github.com/avcodewizard)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance87

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~190 days

Total

3

Last Release

64d ago

Major Versions

1.2.1 → 2.0.02026-04-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e19e6c2cab30c60bcd1f9c6794710aafef9703dccbfb59b346e3f648ca799a9?d=identicon)[avcodewizard](/maintainers/avcodewizard)

---

Top Contributors

[![avcodewizard](https://avatars.githubusercontent.com/u/45030401?v=4)](https://github.com/avcodewizard "avcodewizard (5 commits)")

---

Tags

auto-backupauto-cleanupbackupdatabase-backupdevopslaravellaravel-12laravel-applicationlaravel-frameworklaravel-packagephpphp-frameworkstorage-backupziplaravelbackupdatabase backupstorage backupauto-backupauto-cleanup

### Embed Badge

![Health badge](/badges/avcodewizard-laravel-backup/health.svg)

```
[![Health](https://phpackages.com/badges/avcodewizard-laravel-backup/health.svg)](https://phpackages.com/packages/avcodewizard-laravel-backup)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2831.6M9](/packages/spatie-laravel-prometheus)[ublabs/blade-simple-icons

A package to easily make use of Simple Icons in your Laravel Blade views.

1963.4k](/packages/ublabs-blade-simple-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
