laravel-db-backup maintained by sulaimanbarki
Laravel Database Backup
A lightweight, zero-configuration Laravel package to quickly download your database as an SQL backup file directly from your browser.
Perfect for small-to-medium projects that need a fast, simple, and completely open database backup mechanism without any authorization constraints.
[!CAUTION] Security Warning: This package registers a public route
/backupdbwith no authentication or authorization checks. Anyone who visits this URL will be able to download your entire database. Use with caution or only in protected environments.
🚀 How It Works
- Automatic Route Registration: The package automatically registers a public route at
/backupdb(nameddb-backup.download). - No Authentication Constraints: The route has no restrictions, making it accessible to both guests and authenticated users.
- Smart Backup Generation:
- Queries all database tables safely using
SHOW TABLESand sanitizes identifiers. - Fetches table schemas using
SHOW CREATE TABLE. - Generates fully standard, formatted
INSERT INTOstatements for all records (with proper handling forNULLvalues and SQL escaping).
- Queries all database tables safely using
- Zero Disk Footprint: Streams the backup file (.sql) to the client immediately and deletes the temporary file from the server right after the transfer is complete.
📦 Installation
Install the package via composer:
composer require sulaimanbarki/laravel-db-backup
⚙️ Auto-Discovery
This package uses Laravel's package auto-discovery feature. The service provider sulaimanbarki\DbBackup\DbBackupServiceProvider is automatically registered. You don't need to manually add it to your config/app.php.
🛠️ Usage
Once installed, you can access the backup route /backupdb or dynamically link to it in your templates.
Direct Access
Navigate directly to:
https://your-domain.com/backupdb
Linking in Blade Views
Generate a link to the download page using the route helper:
<a href="{{ route('db-backup.download') }}" class="btn btn-primary">
<i class="fa fa-download"></i> Download Database Backup
</a>
🛠️ Tech Specs & Support
- PHP Version:
^8.0 - Laravel Framework:
^9.0,^10.0, or^11.0 - Database Engine: MySQL / MariaDB (requires support for
SHOW TABLESandSHOW CREATE TABLE).
📄 License
The MIT License (MIT). Please see License File for more information.