Installation:
composer require moox/backup-server
php artisan mooxbackupserver:install
This publishes migrations, config, and sets up Filament resources.
Configure Spatie Backup Server:
config/backup-server.php to define backup sources (e.g., databases, files).~/.ssh/ or via config/backup-server.php.First Use Case:
/admin/backup-server (Filament UI).mysql or filesystem).completed, failed)./resources/views/filament/backup-server/ (customize views if needed).config/backup-server.php (adjust sources, schedules, or storage paths).storage/logs/backup-server.log (debug issues).Automated Backups:
config/backup-server.php:
'schedules' => [
'daily' => [
'command' => 'backup:run --source=mysql --name=daily',
'cron' => '0 2 * * *',
],
],
php artisan schedule:run
Remote Server Backups:
~/.ssh/authorized_keys on destination server).config/backup-server.php:
'connections' => [
'remote-server' => [
'type' => 'ssh',
'host' => 'source-server.example.com',
'username' => 'forge',
'key' => '/path/to/private_key',
],
],
'sources' => [
'remote-mysql' => [
'type' => 'database',
'connection' => 'remote-server',
'database' => 'app_db',
],
],
Filament Integration:
Backup resource to display all backups with metadata (size, duration, status).public static function getActions(Backup $record): array
{
return [
Action::make('restore')
->url(fn (Backup $record) => route('backups.restore', $record))
->icon('heroicon-o-arrow-path'),
];
}
Storage Backends:
S3, FTP, or custom drivers by publishing the config and modifying:
'storage' => [
'disks' => ['local', 's3'],
'default' => 's3',
],
php artisan backup:run --dry-run to validate configurations without creating backups.event(new BackupFailed($backup));
Backup model:
class Backup extends \Moox\BackupServer\Models\Backup
{
protected $casts = [
'custom_metadata' => 'array',
];
}
SSH Key Permissions:
600 permissions:
chmod 600 ~/.ssh/private_key
Connection refused or Permission denied.Filament Caching:
php artisan filament:cache-reset
Storage Paths:
~/Backups/My Backup).'storage' => [
'path' => '/backups/my_backup',
],
Large Backups:
max_execution_time in php.ini or use --chunk flag:
php artisan backup:run --chunk=100
storage/logs/backup-server.log for errors.php artisan backup:run --verbose
ssh -vvv forge@source-server.example.com
Custom Backup Sources:
Moox\BackupServer\Backup\Sources\Source to add new source types (e.g., git repositories):
class GitSource extends Source
{
public function getContents(): string
{
return shell_exec("git --git-dir={$this->path} archive --format=tar HEAD");
}
}
Pre/Post Hooks:
BackupStarting::dispatch($backup);
BackupCompleted::dispatch($backup);
EventServiceProvider:
public function boot()
{
BackupStarting::listen(function ($backup) {
Log::info("Starting backup: {$backup->name}");
});
}
Filament Widgets:
public static function getWidgets(): array
{
return [
BackupStatsWidget::class,
];
}
Default Storage: If storage.path is empty, backups default to storage/app/backups.
Retention Policy: Configure in config/backup-server.php:
'retention' => [
'keep' => 30, // days
'cleanup' => true,
],
Run cleanup manually:
php artisan backup:cleanup
Environment Variables: Override config with .env:
BACKUP_SERVER_STORAGE_PATH=/custom/backups
BACKUP_SERVER_SCHEDULE_DAILY_CRON=0 3 * * *
How can I help you explore Laravel packages today?