A simple Laravel package for backing up MySQL and PostgreSQL databases.
Author: Mahatma Mahardhika mahatma.mahardhika@programinglive.com
- ποΈ Support for MySQL and PostgreSQL databases
- π¦ Easy to install and use
- π― Simple Artisan command for backups
- πΎ Automatic backup file management
- π§ Configurable backup settings
composer require programinglive/laravel-simple-backupPublish 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.
Backup the default database connection:
php artisan backup:databaseBackup a specific database connection:
php artisan backup:database --connection=mysqlOr for PostgreSQL:
php artisan backup:database --connection=pgsqluse 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');use ProgrammingLive\LaravelSimpleBackup\Facades\Backup;
// Backup the database
$filepath = Backup::backup();
// Get all backups
$backups = Backup::getBackups();- PHP 8.1 or higher
- Laravel 9.0, 10.0, 11.0, or 12.0
- MySQL or PostgreSQL with command-line tools installed
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
Backups are stored in the storage/backups directory by default. You can change this in the config/backup.php file.
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
# Run all tests
vendor/bin/phpunit
# Run specific test file
vendor/bin/phpunit tests/BackupManagerTest.php
# Run with coverage
vendor/bin/phpunit --coverage-html coverageTo 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/
Please see CONTRIBUTING.md for details.
If you discover any security-related issues, please email mahatma.mahardhika@programinglive.com instead of using the issue tracker.
MIT License. See LICENSE file for details.
For issues and feature requests, please visit the GitHub repository.