ratoguras / laravel-migrate-backup
Automatically takes a database backup before running migrate:fresh or migrate:refresh
Package info
github.com/Packages-Rato-Guras/laravel-migrate-backup
pkg:composer/ratoguras/laravel-migrate-backup
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/events: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
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.