Documentation

Installation

Install the package via Composer:

composer require programinglive/laravel-simple-backup

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="ProgrammingLive\LaravelSimpleBackup\LaravelSimpleBackupServiceProvider" --tag="backup-config"

Usage

Using Artisan Command

Backup the default database connection:

php artisan backup:database

Backup a specific connection:

php artisan backup:database --connection=mysql

Using BackupManager Class

use ProgrammingLive\LaravelSimpleBackup\BackupManager;

// Create backup
$filepath = BackupManager::backup();

// List all backups
$backups = BackupManager::getBackups();

// Delete a backup
BackupManager::deleteBackup('backup_mydb_2024-12-08_10-00-00.sql');

// Download a backup
$filepath = BackupManager::downloadBackup('backup_mydb_2024-12-08_10-00-00.sql');

Using Facade

use ProgrammingLive\LaravelSimpleBackup\Facades\Backup;

// Create backup
$filepath = Backup::backup();

// List backups
$backups = Backup::getBackups();

Requirements

  • PHP 8.2 or higher
  • Laravel 10.0 or 11.0
  • MySQL with mysqldump installed
  • PostgreSQL with pg_dump installed

Backup File Location

Backups are stored in storage/backups directory by default.

Backup File Format

Backup files are named with the following format:

backup_database_name_YYYY-MM-DD_HH-MM-SS.sql

System Requirements

For MySQL

  • Windows: Usually included with MySQL installation
  • Linux: sudo apt-get install mysql-client
  • macOS: brew install mysql-client

For PostgreSQL

  • Windows: Usually included with PostgreSQL installation
  • Linux: sudo apt-get install postgresql-client
  • macOS: brew install postgresql

Configuration Options

After publishing the config file, you can customize:

// config/backup.php
return [
    'default_connection' => env('DB_CONNECTION', 'mysql'),
    'backup_path' => storage_path('backups'),
    'keep_backups' => env('BACKUP_KEEP_DAYS', 30),
];

Error Handling

The package throws exceptions for invalid connections or unsupported drivers:

try {
    $filepath = BackupManager::backup('invalid_connection');
} catch (Exception $e) {
    echo "Backup failed: " . $e->getMessage();
}

Support

For issues and feature requests, visit the GitHub repository.