programinglive / laravel-simple-backup
A simple Laravel package for backing up MySQL and PostgreSQL databases
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/programinglive/laravel-simple-backup
Requires
- php: ^8.1
- illuminate/config: ^9.0|^10.0|^11.0|^12.0
- illuminate/console: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- phpunit/phpunit: ^9.5|^10.0|^11.0
README
A simple Laravel package for backing up MySQL and PostgreSQL databases.
Author: Mahatma Mahardhika mahatma.mahardhika@programinglive.com
Features
- 🗄️ Support for MySQL and PostgreSQL databases
- 📦 Easy to install and use
- 🎯 Simple Artisan command for backups
- 💾 Automatic backup file management
- 🔧 Configurable backup settings
Installation
composer require programinglive/laravel-simple-backup
Configuration
Publish the configuration file:
php artisan vendor:publish --provider="ProgrammingLive\LaravelSimpleBackup\LaravelSimpleBackupServiceProvider" --tag="backup-config"
This will create a config/backup.php file where you can configure your backup settings.
Usage
Using Artisan Command
Backup the default database connection:
php artisan backup:database
Backup a specific database connection:
php artisan backup:database --connection=mysql
Or for PostgreSQL:
php artisan backup:database --connection=pgsql
Using the Backup Manager Class
use ProgrammingLive\LaravelSimpleBackup\BackupManager; // Backup the default connection $filepath = BackupManager::backup(); // Backup a specific connection $filepath = BackupManager::backup('mysql'); // Get all backups $backups = BackupManager::getBackups(); // Delete a backup BackupManager::deleteBackup('backup_mydb_2024-12-08_10-30-45.sql'); // Download a backup $filepath = BackupManager::downloadBackup('backup_mydb_2024-12-08_10-30-45.sql');
Using the Facade
use ProgrammingLive\LaravelSimpleBackup\Facades\Backup; // Backup the database $filepath = Backup::backup(); // Get all backups $backups = Backup::getBackups();
Requirements
- PHP 8.1 or higher
- Laravel 9.0, 10.0, 11.0, or 12.0
- MySQL or PostgreSQL with command-line tools installed
System Requirements
For MySQL backups, ensure mysqldump is installed:
- Windows: Usually included with MySQL installation
- Linux:
sudo apt-get install mysql-client - macOS:
brew install mysql-client
For PostgreSQL backups, ensure pg_dump is installed:
- Windows: Usually included with PostgreSQL installation
- Linux:
sudo apt-get install postgresql-client - macOS:
brew install postgresql
Backup File Location
Backups are stored in the storage/backups directory by default. You can change this in the config/backup.php file.
Backup File Format
Backup files are named with the following format:
backup_{database_name}_{YYYY-MM-DD_HH-MM-SS}.sql
Example:
backup_myapp_2024-12-08_10-30-45.sql
Testing
Running Tests
# Run all tests vendor/bin/phpunit # Run specific test file vendor/bin/phpunit tests/BackupManagerTest.php # Run with coverage vendor/bin/phpunit --coverage-html coverage
Testing in a Laravel Project
To test this package in a real Laravel project:
-
Create a new Laravel project:
composer create-project laravel/laravel test-backup-app cd test-backup-app -
Add the package as a local repository in
composer.json:"repositories": [ { "type": "path", "url": "../laravel-simple-backup" } ]
-
Install the package:
composer require programinglive/laravel-simple-backup:@dev
-
Configure your database in
.envand run:php artisan backup:database
-
Check the backup file in
storage/backups/
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security-related issues, please email mahatma.mahardhika@programinglive.com instead of using the issue tracker.
License
MIT License. See LICENSE file for details.
Support
For issues and feature requests, please visit the GitHub repository.