programinglive/laravel-simple-backup
最新稳定版本:v0.0.3
Composer 安装命令:
composer require programinglive/laravel-simple-backup
包简介
A simple Laravel package for backing up MySQL and PostgreSQL databases
README 文档
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.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-08