Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Spatie Laravel Backup Laravel Package

shuvroroy/filament-spatie-laravel-backup

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Package
    composer require shuvroroy/filament-spatie-laravel-backup
    
  2. Publish Assets & Translations
    php artisan filament:assets
    php artisan vendor:publish --tag="filament-spatie-backup-translations"
    
  3. Register the Plugin Add to app/Providers/Filament/AdminPanelProvider.php:
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \ShuvroRoy\FilamentSpatieBackup\Plugin::make(),
            ]);
    }
    
  4. First Use Case Access the backup page via Filament’s sidebar (under "Tools" or a custom section). Run an on-demand backup to test:
    • Select backup type (database, files, or both).
    • Configure storage (local, S3, etc.) via Spatie’s config (config/backup.php).
    • Trigger the backup and verify the download link or storage path.

Implementation Patterns

Core Workflows

  1. Integrating with Existing Backups

    • Use Spatie’s BackupService to extend functionality. Example:
      use Spatie\Backup\Tasks\Backup\BackupTask;
      use Spatie\Backup\Tasks\Backup\DatabaseTask;
      
      $backupTask = new BackupTask(
          'custom-backup-name',
          [
              new DatabaseTask(),
              // Add custom tasks (e.g., custom files, queues)
          ]
      );
      
    • Register in config/backup.php under tasks.
  2. Automated Backups via Filament

    • Schedule backups using Filament’s Scheduled Backup widget:
      Plugin::make()
          ->schedule(Carbon::now()->addDay()) // Set cron-like schedule
          ->notifyVia('slack') // Optional: Add notifications
      
  3. Customizing the UI

    • Override the Filament page by publishing views:
      php artisan vendor:publish --tag="filament-spatie-backup-views"
      
    • Modify resources/views/vendor/filament-spatie-backup/... to add fields (e.g., custom backup paths).
  4. Storage Integration

    • Configure storage in config/backup.php:
      'disks' => [
          's3' => [
              'driver' => 's3',
              'bucket' => env('AWS_BUCKET'),
              'key' => env('AWS_KEY'),
              // ...
          ],
      ],
      
    • Use Filament’s Storage Selector to let admins choose destinations dynamically.
  5. Notifications & Alerts

    • Extend Spatie’s BackupWasSuccessful/BackupFailed events to trigger Filament notifications:
      event(new \Spatie\Backup\Events\BackupWasSuccessful($backup));
      // In Filament, use `Notification::make()->title('Backup Success')`
      

Gotchas and Tips

Pitfalls

  1. Permission Issues

    • Ensure the backup directory (storage/backups) is writable:
      chmod -R 755 storage/backups
      
    • For S3/remote storage, verify IAM roles or API keys have proper permissions.
  2. Large Database Backups

    • Use max-backup-size in config/backup.php to split backups:
      'max-backup-size' => '500M', // Split into chunks
      
    • Monitor memory usage; consider pcntl_signal for long-running backups.
  3. Filament Plugin Registration

    • If the plugin doesn’t appear, check:
      • The AdminPanelProvider is updated.
      • No PHP errors in storage/logs/laravel.log (common: missing filament:assets).
  4. Translation Conflicts

    • If translations don’t load, republish:
      php artisan vendor:publish --tag="filament-spatie-backup-translations" --force
      

Debugging Tips

  • Log Backups: Enable Spatie’s debug mode in config/backup.php:
    'debug' => env('BACKUP_DEBUG', false),
    
  • Test Locally: Use BackupTask::createTestTask() to simulate backups without storage:
    $task = BackupTask::createTestTask('test-backup');
    $task->run();
    
  • Check Events: Listen to BackupStarting, BackupFinished events for debugging:
    BackupWasSuccessful::dispatch($backup);
    

Extension Points

  1. Custom Backup Types

    • Extend Spatie\Backup\Tasks\Backup\BackupTask to add custom logic (e.g., API exports):
      class CustomBackupTask extends BackupTask
      {
          public function __construct()
          {
              parent::__construct('custom-backup', [
                  new DatabaseTask(),
                  new \App\Tasks\ExportApiDataTask(),
              ]);
          }
      }
      
  2. Filament Policy Integration

    • Restrict backup access via Filament’s policies:
      public static function getPages(): array
      {
          return [
              \ShuvroRoy\FilamentSpatieBackup\Pages\BackupPage::class,
          ];
      }
      
      // app/Policies/BackupPolicy.php
      public function viewAny(User $user): bool
      {
          return $user->isAdmin();
      }
      
  3. Webhook Notifications

    • Use Spatie’s BackupWasSuccessful event to send webhooks:
      BackupWasSuccessful::dispatch($backup)
          ->then(function () {
              Http::post('https://your-webhook-url', ['backup' => $backup->name]);
          });
      
  4. Backup Retention

    • Configure retention in config/backup.php:
      'retention_days' => 7, // Keep backups for 7 days
      
    • Override globally or per-task:
      $task->retentionDays(30);
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope