ratoguras/laravel-migrate-backup

Automatically takes a database backup before running migrate:fresh or migrate:refresh

Maintainers

Package info

github.com/Packages-Rato-Guras/laravel-migrate-backup

pkg:composer/ratoguras/laravel-migrate-backup

Statistics

Installs: 18

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-02-13 11:22 UTC

This package is auto-updated.

Last update: 2026-03-13 11:41:39 UTC


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:

  1. Detects default DB connection
  2. Creates backup directory (if missing)
  3. Generates timestamped dump
  4. 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/backups to .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!

  1. Fork the repo
  2. Create feature branch
  3. Commit changes
  4. 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.