Laravel Database Backup is a robust, extensible package for Laravel that simplifies backing up your MySQL and PostgreSQL databases. Built with clean, object-oriented principles, this package offers scheduled backups, multi-storage support, and automatic cleanup of old backups.
- Scheduled Backups: Easily schedule backups daily, weekly, or monthly using Laravel's scheduler.
- Multi-Storage Support: Store backups locally—with the option to add remote storage drivers (e.g., S3, Google Drive) in the future.
- Automatic Cleanup: Automatically delete backups older than a specified retention period to save disk space.
- Artisan Command: Trigger backups manually using a simple Artisan command.
- Custom Exception Handling: Domain-specific error handling with custom exceptions.
- Extensible Architecture: Clean, modular design for easy integration and future enhancements.
Install the package via Composer:
composer require sukhrobnurali/laravel-db-backup
Publish the configuration file:
php artisan vendor:publish --tag=config --provider="LaravelDbBackup\Providers\DatabaseBackupServiceProvider"
The configuration file (config/backup.php
) allows you to customize several aspects of the package:
- Local Storage: Specify the directory where backups will be stored.
- Remote Storage (Stub): Configure remote storage options for future expansion.
- Retention Policy: Set the number of days to retain backups.
- Scheduling: Use cron expressions to schedule your backups.
- Notifications (Stub): Configure notification options (e.g., via Telegram) for backup events.
To manually run a backup, simply execute the Artisan command:
php artisan backup:run
To schedule automatic backups, add the command to your Laravel scheduler in app/Console/Kernel.php
:
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->daily();
}
This package includes a comprehensive test suite using Orchestra Testbench. To run the tests, execute:
vendor/bin/phpunit
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Write tests and ensure that everything passes.
- Submit a pull request.
This package is open-sourced software licensed under the MIT license.