ratoguras/laravel-migrate-backup
最新稳定版本:v1.0.2
Composer 安装命令:
composer require ratoguras/laravel-migrate-backup
包简介
Automatically takes a database backup before running migrate:fresh or migrate:refresh
README 文档
README
Automatically create a database backup before running destructive migration commands like migrate:fresh and migrate:refresh.
This package ensures your data is always safe by generating a timestamped SQL dump before migrations execute.
✨ Features
- 🔄 Auto backup before
migrate:fresh - 🔄 Auto backup before
migrate:refresh - 🏷️ Timestamped backup files
- 📂 Custom backup directory support
- 🧩 Works with migration flags (
--seed, etc.) - 🐬 MySQL / MariaDB support
- 🐘 PostgreSQL support
- 📦 SQLite file backup
- ⚡ Laravel Auto-Discovery ready
- 🛠️ Laravel 10 / 11 / 12 compatible
📦 Installation
Install via Composer:
composer require ratoguras/laravel-migrate-backup
⚙️ Publish Configuration
php artisan vendor:publish --tag=migrate-backup-config
This will publish:
config/migrate-backup.php
🧾 Configuration
<?php return [ /* |-------------------------------------------------------------------------- | Commands to Watch |-------------------------------------------------------------------------- | | Backups will run before these artisan commands execute. | */ 'commands' => [ 'migrate:fresh', 'migrate:refresh', ], /* |-------------------------------------------------------------------------- | Backup Path |-------------------------------------------------------------------------- | | Relative to project base path. | */ 'path' => 'database/backups', ];
🚀 Usage
Run migrations as usual:
php artisan migrate:fresh
or
php artisan migrate:fresh --seed
or
php artisan migrate:refresh
Before execution, the package will automatically generate a backup.
📂 Backup Location
database/backups/
Example file:
mydatabase_2026-02-13_18-45-10.sql
🗄️ Supported Databases
| Database | Supported |
|---|---|
| MySQL | ✅ |
| MariaDB | ✅ |
| PostgreSQL | ✅ |
| SQLite | ✅ |
🧠 How It Works
The package listens to Laravel’s console event:
Illuminate\Console\Events\CommandStarting
When a configured migration command is detected, it:
- Detects default DB connection
- Creates backup directory (if missing)
- Generates timestamped dump
- Stores SQL file safely
📋 Requirements
- PHP ≥ 8.2
- Laravel ≥ 10.x
🧪 Testing Backup
Run:
php artisan migrate:fresh
You should see:
✅ Database backup created: yourdb_2026-02-13_18-50-22.sql
🔐 Security Note
Backups may contain sensitive data.
Recommended:
- Add
/database/backupsto.gitignore - Store backups securely in production
🛣️ Roadmap
Planned features:
- 🔁 Backup restore command
- 🗜️ ZIP compression
- 🧹 Auto cleanup scheduler
- ☁️ Cloud backup support
- 🪟 Windows dump compatibility
🤝 Contributing
Contributions are welcome!
- Fork the repo
- Create feature branch
- Commit changes
- Submit PR
🐞 Issues
Report bugs or request features:
👉 https://github.com/Packages-Rato-Guras/laravel-migrate-backup/issues
📄 License
MIT License © 2026 Adish Dahal
👨💻 Author
Adish Dahal Founder & CEO — Rato Guras Technology Pvt. Ltd.
⭐ Support
If you find this package useful, please ⭐ the repository and share it with the Laravel community.
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-13