cyberwizard/dbsafeguard
Composer 安装命令:
composer require cyberwizard/dbsafeguard
包简介
A Laravel package for safeguarding your database with easy-to-use backup commands.
README 文档
README
DBSafeGuard is a Laravel package that provides a convenient command-line interface to back up your database. It supports MySQL and PostgreSQL databases, and allows you to save backups locally or upload them directly to AWS S3.
What's New in 1.3.0
- Progress Bars: Added visual progress bars for both local database dumping and S3 uploading.
- Backup Retention: Automatically clean up old backups to save storage. Keep the latest backups based on the new
MAX_BACKUPSenvironment variable (defaults to 3).
What's New in 1.2.1
- Memory Optimization: Fixed a memory exhaustion issue when uploading large database backups to S3 by using file streams.
What's New in 1.1.0
- Laravel 12 Support: Fully compatible with Laravel 9.0 through 12.0+.
- PostgreSQL Support: Automatically detects your connection and supports
pg_dump. - S3 Uploads: Stream backups directly to AWS S3 using the new
--disk=s3flag.
Requirements
- PHP 8.0 or higher
- Laravel 9.0, 10.0, 11.0, or 12.0+
mysqldumporpg_dumpinstalled on your server (depending on your database)
Installation
Install the package via Composer:
composer require cyberwizard/dbsafeguard
If you are installing directly from the GitHub repository, add the following to your composer.json first:
"repositories": [ { "type": "vcs", "url": "https://github.com/cyberwizard-dev/DBSafeGuard" } ]
Then run composer require cyberwizard/dbsafeguard:dev-main.
Configuration
The package automatically uses your standard Laravel database configuration. Ensure the standard environment variables are set in your .env file:
DB_CONNECTION=mysql # or pgsql DB_HOST=127.0.0.1 DB_PORT=3306 # or 5432 DB_DATABASE=your_database DB_USERNAME=your_username DB_PASSWORD=your_password
S3 Configuration
If you plan to upload your backups to AWS S3, you must configure your S3 credentials in your .env file:
AWS_ACCESS_KEY_ID=your_access_key AWS_SECRET_ACCESS_KEY=your_secret_key AWS_DEFAULT_REGION=your_region AWS_BUCKET=your_bucket_name
Backup Retention
By default, the package will keep the latest 3 backups and automatically delete older ones to save storage space. You can change this limit by setting the MAX_BACKUPS environment variable in your .env file:
MAX_BACKUPS=5
Usage
Local Backup
To back up your database to the local disk, run:
php artisan backup:db
The command will prompt you for a backup path. If you accept the default, the backup file will be stored in the storage/app/backups directory with a timestamped filename.
S3 Backup
To back up your database and upload it directly to S3, use the --disk option:
php artisan backup:db --disk=s3
This will create a temporary local dump, upload it to the backups/ directory in your S3 bucket, and then remove the local temporary file.
Scheduled Backups
You can schedule automatic backups using Laravel's task scheduler. Add the following to your console routes or App\Console\Kernel class:
// Local backup daily at midnight Schedule::command('backup:db')->daily(); // S3 backup twice daily Schedule::command('backup:db --disk=s3')->twiceDaily(1, 13);
Author
Cyberwizard
Contact: eminibest@gmail.com
License
This package is open-sourced software licensed under the MIT license.
cyberwizard/dbsafeguard 适用场景与选型建议
cyberwizard/dbsafeguard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.05k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cyberwizard/dbsafeguard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cyberwizard/dbsafeguard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-20