PHPackages                             blalmal10-a/db-zip - 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. [Database &amp; ORM](/categories/database)
4. /
5. blalmal10-a/db-zip

ActiveLibrary[Database &amp; ORM](/categories/database)

blalmal10-a/db-zip
==================

Easily backup and restore laravel database tables by saving them into zip files.

v1.0.1(1mo ago)05↓80%[2 PRs](https://github.com/blalmal10a/db-zip/pulls)MITPHPPHP ^8.2CI passing

Since Jun 10Pushed 1mo agoCompare

[ Source](https://github.com/blalmal10a/db-zip)[ Packagist](https://packagist.org/packages/blalmal10-a/db-zip)[ Docs](https://github.com/blalmal10a/db-zip)[ GitHub Sponsors](https://github.com/blalmal10a)[ RSS](/packages/blalmal10-a-db-zip/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (14)Versions (9)Used By (0)

Easily backup and restore Laravel database tables by saving them into zip files.
================================================================================

[](#easily-backup-and-restore-laravel-database-tables-by-saving-them-into-zip-files)

[![Latest Version on Packagist](https://camo.githubusercontent.com/493b941364b66644f0bbe0eb966f59b9c023ea308a1c9c9c5e338c0837b82ac3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626c616c6d616c31302d612f64622d7a69702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blalmal10-a/db-zip)[![Fix PHP code style issues](https://github.com/blalmal10a/db-zip/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/blalmal10a/db-zip/actions/workflows/fix-php-code-style-issues.yml)[![run-tests](https://github.com/blalmal10a/db-zip/actions/workflows/run-tests.yml/badge.svg)](https://github.com/blalmal10a/db-zip/actions/workflows/run-tests.yml)[![PHPStan](https://github.com/blalmal10a/db-zip/actions/workflows/phpstan.yml/badge.svg)](https://github.com/blalmal10a/db-zip/actions/workflows/phpstan.yml)[![Total Downloads](https://camo.githubusercontent.com/c80c84f459bcba423d2394bb10c8036ce4d6e65ff35d1a4fdffd2465e9a5f486/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626c616c6d616c3130612f64622d7a69702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blalmal10a/db-zip)

**db-zip** exports database tables into chunked CSV files (400 rows per chunk), packages them into a zip with schema JSON, and can restore tables from those zip files — all through a web UI or API.

Installation
------------

[](#installation)

```
composer require blalmal10-a/db-zip
```

The package works immediately after installation — no migrations, no setup required.\\

- You can simply go to /backup to backup your current database
- And /restore to restore the exported .zip files

### Optional — Publish config (to customise behaviour)

[](#optional--publish-config-to-customise-behaviour)

```
php artisan vendor:publish --tag="db-zip-config"
```

### Optional — Publish views (to customise the UI)

[](#optional--publish-views-to-customise-the-ui)

```
php artisan vendor:publish --tag="db-zip-views"
```

Views are published to `resources/views/vendor/db-zip/`. Your layout can extend or replace `db-zip::layouts.app`.

Views load Tailwind CSS and Alpine.js via CDN. No npm setup required.

Default behaviour
-----------------

[](#default-behaviour)

BehaviourDefaultAuth requiredYes — routes use `web` + `auth` middlewareRole required`super_admin` (via Spatie Laravel Permission)Storage paths`storage/backup/` (CSV temp) and `storage/zip/` (zip archives)Route prefixNone — routes sit at `/backup`, `/restore`Authentication &amp; role access
--------------------------------

[](#authentication--role-access)

Out of the box, all routes require an **authenticated user** with the **`super_admin` role** (via `spatie/laravel-permission`).

### Quick role setup

[](#quick-role-setup)

```
composer require spatie/laravel-permission
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate
```

Add the `HasRoles` trait to your `User` model:

```
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}
```

Create the role and assign to a user:

```
php artisan tinker --execute '
    Spatie\Permission\Models\Role::create(["name" => "super_admin"]);
    $user = App\Models\User::find(1);
    $user->assignRole("super_admin");
'
```

### Bypassing or customising auth / roles

[](#bypassing-or-customising-auth--roles)

You have full control via the published config. Run:

```
php artisan vendor:publish --tag="db-zip-config"
```

Then edit `config/db-zip.php`:

```
// Disable role checks entirely
'required_roles' => [],

// Change the required roles to any set you want
'required_roles' => ['admin', 'backup-operator'],

// Change the middleware applied to all routes
'middleware_group' => ['web'], // no auth middleware — accessible to all

// Or use your own custom middleware group
'middleware_group' => ['web', 'auth', 'custom-backup-guard'],
```

If you use a completely different authorisation system, you can also point the routes to your own controller classes:

```
'controllers' => [
    'backup' => App\Http\Controllers\MyBackupController::class,
    'restore' => App\Http\Controllers\MyRestoreController::class,
],
```

> Your custom controllers must implement the same public methods as the originals. Extend the package controllers and override only what you need:

```
namespace App\Http\Controllers;

use Blalmal10a\DbZip\Http\Controllers\BackupController as BaseBackupController;

class MyBackupController extends BaseBackupController
{
    // override any method
}
```

Configuration reference
-----------------------

[](#configuration-reference)

Published config `config/db-zip.php`:

```
return [
    'backup_path' => env('DBZIP_BACKUP_PATH', 'backup'),
    'zip_path' => env('DBZIP_ZIP_PATH', 'zip'),
    'required_roles' => ['super_admin'],
    'middleware_group' => ['web', 'auth'],
    'route' => [
        'backup_index' => '/backup',
        'backup_tables' => '/backup/tables',
        'backup_export' => '/backup/export',
        'backup_zip' => '/backup/zip',
        'backup_download' => '/backup/download/{fileName}',
        'backup_delete' => '/backup/{fileName}',
        'restore_index' => '/restore',
        'backup_restore' => '/backup/restore',
    ],
    'controllers' => [
        'backup' => Blalmal10a\DbZip\Http\Controllers\BackupController::class,
        'restore' => Blalmal10a\DbZip\Http\Controllers\RestoreController::class,
    ],
];
```

Override paths via `.env`:

```
DBZIP_BACKUP_PATH=backup
DBZIP_ZIP_PATH=zip
```

Routes
------

[](#routes)

MethodURINameGET`/backup``backup.index`GET`/backup/tables``backup.tables`POST`/backup/export``backup.export`POST`/backup/zip``backup.zip`GET`/backup/download/{fileName}``backup.download`DELETE`/backup/{fileName}``backup.delete`GET`/restore``restore.index`POST`/backup/restore``backup.restore`All routes are wrapped in the middleware group from `config('db-zip.middleware_group')` plus a `backup-role` check.

Change any route path in the published config without touching the route file.

Usage
-----

[](#usage)

### Via browser

[](#via-browser)

Visit `/backup` to see available tables, export them, and manage zip files. Visit `/restore` to upload a zip, view chunked CSVs grouped by table, and restore data.

### Via API

[](#via-api)

```
# List tables
curl http://your-app.test/backup/tables

# Export a table
curl -X POST http://your-app.test/backup/export \
  -H "Content-Type: application/json" \
  -d '{"table":"users","connection":"mysql"}'

# Zip the exported CSVs
curl -X POST http://your-app.test/backup/zip \
  -H "Content-Type: application/json" \
  -d '{"timestamp":"2025-01-01_120000"}'

# Download a backup
curl -O http://your-app.test/backup/download/2025-01-01_120000

# Upload and restore
curl -X POST http://your-app.test/backup/restore \
  -F "zip=@2025-01-01_120000.zip" \
  -F "append=false"
```

### Using PHP

[](#using-php)

```
use Blalmal10a\DbZip\DbZip;

$dbZip = app(DbZip::class);

$dbZip->exportTableToCsv('users', now()->format('Y-m-d_Hi'));
$dbZip->zipBackup('2025-01-01_120000');

$backups = $dbZip->listBackups();
$path = $dbZip->downloadBackup('2025-01-01_120000');
$dbZip->deleteBackup('2025-01-01_120000');
$dbZip->restoreTable('users', $csvContent, $tableSQL, append: false);
```

Storage
-------

[](#storage)

Backup CSVs and zip files are stored in `storage_path(config('db-zip.backup_path'))` and `storage_path(config('db-zip.zip_path'))` respectively — outside `public/` by default. Downloads are served through Laravel, not directly by the web server.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [blalmal10a](https://github.com/blalmal10a)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance92

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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 ~0 days

Total

5

Last Release

46d ago

Major Versions

v0.1.0 → v1.0.02026-06-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/45043442?v=4)[B. Lalmalsawma](/maintainers/blalmal10a)[@blalmal10a](https://github.com/blalmal10a)

---

Top Contributors

[![blalmal10a](https://avatars.githubusercontent.com/u/45043442?v=4)](https://github.com/blalmal10a "blalmal10a (49 commits)")

---

Tags

laravelblalmal10adb-zip

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/blalmal10-a-db-zip/health.svg)

```
[![Health](https://phpackages.com/badges/blalmal10-a-db-zip/health.svg)](https://phpackages.com/packages/blalmal10-a-db-zip)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M48](/packages/spatie-laravel-pdf)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

213427.0k2](/packages/wnx-laravel-backup-restore)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.8k](/packages/rawilk-profile-filament-plugin)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17558.6k](/packages/lacodix-laravel-model-filter)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

557.9k](/packages/giacomomasseron-laravel-models-generator)

PHPackages © 2026

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