aaix/laravel-easy-backups
Developer-first Laravel backup package with an interactive CLI wizard, direct Artisan commands for automation, and a fluent API to build custom workflows. Create/restore DB backups, choose destinations, enable compression, and control retention.
Installation
composer require aaix/laravel-easy-backups
php artisan vendor:publish --provider="Aaix\EasyBackups\EasyBackupsServiceProvider" --tag="config"
config/easy-backups.php.First Backup
use Aaix\EasyBackups\Facades\EasyBackups;
EasyBackups::run(); // Creates a backup in storage path (default: `storage/app/backups`)
storage/app/backups/ for generated .sql or .gz files.Key Config
config/easy-backups.php for:
backup_path (default: storage/app/backups)compression (default: gzip)database (default: mysql, but supports pgsql, sqlite)// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command(EasyBackups::class)
->dailyAt('2:00') // Runs at 2 AM daily
->withoutOverlapping();
}
php artisan schedule:run manually or use Laravel Forge/Forge.EasyBackups::run()
->database('pgsql') // Override default DB
->compress('zip') // Force ZIP compression
->excludeTables(['password_resets', 'sessions'])
->withFilename('custom_backup_' . now()->format('Y-m-d'))
->run(); // Execute
// Configure in config/easy-backups.php
'storage' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'bucket' => 'my-backup-bucket',
'path' => 'laravel/backups',
],
// Listen for backup completion
EasyBackups::listen(function ($backup) {
Log::info("Backup created: {$backup->filename}");
// Send Slack notification, etc.
});
EasyBackups::run()
->incremental() // Only backups changed data (MySQL only)
->run();
$backup = EasyBackups::run()->verify();
if ($backup->isValid()) {
// Proceed with backup
}
Database-Specific Quirks
pg_dump CLI tool. Ensure it’s installed on the server.
EasyBackups::run()->database('pgsql')->withBinary('pg_dump');
--where) may fail on large tables.Permissions
storage/app/backups is writable:
chmod -R 775 storage/app/backups
Large Databases
--quick flag for MySQL to skip table locks (but slower):
EasyBackups::run()->database('mysql')->withOptions(['quick']);
Timeouts
max_execution_time. Use queues:
EasyBackups::run()->dispatch(); // Dispatches to queue
'debug' => env('BACKUP_DEBUG', false),
EasyBackups::run()->dryRun()->run();
try {
EasyBackups::run()->run();
} catch (\Exception $e) {
Log::error("Backup failed: " . $e->getMessage());
}
Filename Customization
EasyBackups::run()
->withFilename(fn () => 'backup_' . Str::uuid())
->run();
Backup Retention Policy Combine with Laravel’s filesystem cleanup:
// app/Console/Commands/CleanBackups.php
public function handle()
{
Storage::disk('backups')->delete(
Storage::disk('backups')->files('', true)
->filter(fn ($file) => now()->diffInDays($file->lastModified()) > 7)
);
}
Multi-Database Backups
EasyBackups::run()
->database('mysql', ['connection' => 'mysql_secondary'])
->run();
Extension Points
BackupStarting, BackupCompleted).Aaix\EasyBackups\Contracts\BackupDriver for unsupported DBs.CI/CD Integration
# In GitHub Actions
- name: Run backups
run: php artisan easy-backups:run --filename="ci_backup_$(date +%s)"
How can I help you explore Laravel packages today?