mikailfaruqali/backup 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

License: MIT

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_name and zip_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) using config([...]) 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/mysqldump or /usr/local/bin/mysqldump

How it Works

Under the hood (simplified):

  1. Create a temporary .sql dump using spatie/db-dumper and mysqldump.
  2. Create a temporary .zip with ZipArchive, set password and AES‑256 encryption, add the SQL file.
  3. Stream the ZIP to the client as the response filename from file_name.
  4. Delete the temporary files after streaming.

Troubleshooting

  • ZIP won't open / wrong password

    • Verify zip_password in config/snawbar-backup.php
    • Ensure no whitespace or unexpected characters
  • 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_path to the absolute path of mysqldump
    • Ensure the PHP user can execute mysqldump
  • Empty or partial dump

    • Check DB credentials in config/database.php
    • Large databases may require increasing PHP max_execution_time and memory limits
  • Route not found

    • Clear caches: php artisan route:clear; php artisan config:clear
    • Confirm your app is loading package routes and provider (auto-discovery)

Limitations and Notes

  • Currently supports the default mysql connection. 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 as config/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 我们能提供哪些服务?
定制开发 / 二次开发

基于 mikailfaruqali/backup 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 89
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-01