mikailfaruqali/backup
Composer 安装命令:
composer require mikailfaruqali/backup
包简介
Generate on-demand MySQL database backups and download them as password-protected, AES‑256 encrypted ZIP files via a simple HTTP route.
README 文档
README
Generate on-demand MySQL database backups and download them as password-protected, AES‑256 encrypted ZIP files via a simple HTTP route.
Built for simplicity, performance, and easy integration into existing Laravel apps.
Features
- One-click/download database backup via HTTP route
- ZIP encryption using AES‑256 (ZipArchive::EM_AES_256)
- Password protection for the ZIP file
- Configurable route prefix and middleware
- Customizable download filename
- Support for custom mysqldump binary path (Windows/Linux/macOS)
- Streams response and cleans up temporary files automatically
Requirements
- PHP >= 7.4
- Laravel framework (or illuminate/contracts) >= 5.0
- PHP ZipArchive extension enabled
- MySQL database connection configured in
config/database.php - spatie/db-dumper (installed as a dependency)
Installation
Install via Composer:
composer require mikailfaruqali/backup
Laravel will auto-discover the service provider.
Configuration
Publish the configuration file to your app (it will create config/snawbar-backup.php):
php artisan vendor:publish --provider="Snawbar\Backup\BackupServiceProvider" --tag="snawbar-backup-config"
Available options (defaults shown):
return [ // Middleware applied to the backup route(s) 'middleware' => ['web'], // Route prefix used by the package 'route' => 'backup', // The downloadable ZIP file name (string). Avoid closures when using config cache. 'file_name' => 'backup.zip', // The password required to open the ZIP 'zip_password' => 'snawbar', // Absolute path to mysqldump if it's not in PATH // e.g. Windows: 'C:/xampp/mysql/bin/mysqldump.exe' // Linux/macOS: '/usr/bin/mysqldump' 'mysql_dump_path' => '', ];
Notes:
- The package code will also accept callables for
file_nameandzip_password. However, Laravel's config cache cannot serialize closures. Prefer static strings in your config file. If you need dynamic values, set them at runtime (e.g., in middleware) usingconfig([...])before the request hits the controller, and avoid caching config or provide a non-closure value when cached.
Routes and Usage
This package registers the following route by default:
- GET
/{prefix}/download→ streams a password-protected ZIP containing a MySQL dump
Where {prefix} is the value of snawbar-backup.route (default: backup).
Examples:
- Default URL:
/backup/download - Custom prefix
admin/backup:/admin/backup/download
The route name is snawbar.backup.download.
Downloading a backup
- Visit the route in your browser, e.g.
https://your-app.test/backup/download - Or using curl:
curl -L -o backup.zip https://your-app.test/backup/download
The response is a streamed download of an encrypted ZIP whose filename is taken from snawbar-backup.file_name. Use the password from snawbar-backup.zip_password to open the archive.
Security and Access Control
The download route is as secure as the middleware you attach to it. By default it uses the web middleware group only. You should restrict access in production.
Recommended options:
- Require authentication: set
'middleware' => ['web', 'auth'] - Restrict to authorized roles/abilities:
'middleware' => ['web', 'auth', 'can:download-backup'] - Use IP allow-lists or custom middleware for extra checks
- Consider signed routes or additional secrets when exposing via the internet
Update config/snawbar-backup.php accordingly and clear caches:
php artisan config:clear; php artisan route:clear
Database Connection
Backups use your default mysql connection from config/database.php:
- Host:
database.connections.mysql.host - Database:
database.connections.mysql.database - Username:
database.connections.mysql.username - Password:
database.connections.mysql.password
Ensure these are set (typically via your .env).
mysqldump Path (especially on Windows)
If mysqldump isn't available in the system PATH, set mysql_dump_path in config/snawbar-backup.php:
- Windows (XAMPP example):
C:/xampp/mysql/bin/mysqldump.exe - WSL/Linux:
/usr/bin/mysqldump - macOS (Homebrew):
/opt/homebrew/bin/mysqldumpor/usr/local/bin/mysqldump
How it Works
Under the hood (simplified):
- Create a temporary
.sqldump using spatie/db-dumper andmysqldump. - Create a temporary
.zipwith ZipArchive, set password and AES‑256 encryption, add the SQL file. - Stream the ZIP to the client as the response filename from
file_name. - Delete the temporary files after streaming.
Troubleshooting
-
ZIP won't open / wrong password
- Verify
zip_passwordinconfig/snawbar-backup.php - Ensure no whitespace or unexpected characters
- Verify
-
500 error: Failed to create ZIP archive
- Confirm PHP ZipArchive extension is installed and enabled
- Ensure the PHP process can write to the temp directory (
sys_get_temp_dir())
-
mysqldump not found or permission denied
- Set
mysql_dump_pathto the absolute path ofmysqldump - Ensure the PHP user can execute
mysqldump
- Set
-
Empty or partial dump
- Check DB credentials in
config/database.php - Large databases may require increasing PHP
max_execution_timeand memory limits
- Check DB credentials in
-
Route not found
- Clear caches:
php artisan route:clear; php artisan config:clear - Confirm your app is loading package routes and provider (auto-discovery)
- Clear caches:
Limitations and Notes
- Currently supports the default
mysqlconnection. For other drivers, extend the controller as needed. - Configuration closures are not compatible with
php artisan config:cache. - The backup is generated on-demand per request; there's no scheduled/queued command included by default.
API Surface (Package Internals)
- Service Provider:
Snawbar\Backup\BackupServiceProvider - Controller:
Snawbar\Backup\Http\Controllers\BackupController - Route file:
src/routes/web.php - Config file:
config/backup.php(published asconfig/snawbar-backup.php)
Contributing
Issues and PRs are welcome. Please run code style and static analysis before submitting.
vendor\bin\pint vendor\bin\phpstan analyse
License
This package is open-sourced software licensed under the MIT license.
Author
Snawbar — alanfaruq85@gmail.com
Links
mikailfaruqali/backup 适用场景与选型建议
mikailfaruqali/backup 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 89 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「encryption」 「backup」 「laravel」 「zip」 「snawbar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mikailfaruqali/backup 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mikailfaruqali/backup 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mikailfaruqali/backup 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
A SDK for working with B2 cloud storage.
Store your language lines in the database, yaml or other sources
A simple PHP class to encrypt a string and decrypt an encrypted string
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Encryption with AES-256 and HMAC-SHA256
统计信息
- 总下载量: 89
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-01