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

Backup Manager Symfony Laravel Package

branlute/backup-manager-symfony

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Run:

    composer require backup-manager/symfony
    

    The bundle auto-registers via Symfony Flex.

  2. First Configuration Define a backup job in config/packages/backup_manager.yaml:

    backup_manager:
        jobs:
            my_db_backup:
                type: db
                name: "My Database Backup"
                storage:
                    type: local
                    directory: "%kernel.project_dir%/var/backups"
                schedule: "0 2 * * *" # Runs daily at 2 AM
    
  3. First Run Trigger manually via CLI:

    php bin/console backup:run my_db_backup
    

    Verify backups appear in var/backups.

Where to Look First

  • Configuration: config/packages/backup_manager.yaml (default paths, jobs, storage).
  • Commands: php bin/console list backup (list available commands).
  • Storage Adapters: config/packages/backup_manager.yaml under storage (S3, Dropbox, etc.).

Implementation Patterns

Core Workflows

  1. Defining Jobs

    • Database Backups:
      jobs:
          daily_db:
              type: db
              name: "Daily DB Backup"
              storage: { type: s3, ... }
              options:
                  db_dsn: "mysql://user:pass@localhost/db"
      
    • Filesystem Backups:
      jobs:
          app_files:
              type: filesystem
              name: "App Files Backup"
              storage: { type: dropbox, ... }
              options:
                  source: "%kernel.project_dir%/var"
      
  2. Storage Integration Configure cloud storage in backup_manager.yaml:

    storage:
        s3:
            key: "%env(S3_KEY)%"
            secret: "%env(S3_SECRET)%"
            bucket: "my-backups"
        dropbox:
            token: "%env(DROPBOX_TOKEN)%"
    
  3. Scheduling Use Symfony’s cron or a scheduler like Laravel Horizon (via backup:run command in a queue job).

  4. Post-Backup Actions Extend with event listeners (e.g., notify Slack on failure):

    // src/EventListener/BackupListener.php
    namespace App\EventListener;
    
    use BackupManager\Event\BackupEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class BackupListener implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                'backup.post' => 'onBackupComplete',
            ];
        }
    
        public function onBackupComplete(BackupEvent $event)
        {
            if ($event->getResult()->isSuccess()) {
                // Send Slack notification
            }
        }
    }
    

Integration Tips

  • Laravel-Specific: Use artisan alias for commands:
    php artisan backup:run my_db_backup
    
  • Environment Variables: Store secrets in .env (e.g., S3_KEY=...).
  • Testing: Mock storage adapters in PHPUnit:
    $this->backupManager->setStorage(new MockStorage());
    

Gotchas and Tips

Pitfalls

  1. Storage Permissions

    • Local Storage: Ensure var/backups is writable:
      chmod -R 775 var/backups
      
    • Cloud Storage: Validate credentials early (e.g., test S3 connection via aws s3 ls).
  2. Database Connection Issues

    • Use a dedicated backup user with SELECT privileges only.
    • Test DSN locally before deploying:
      php bin/console backup:run my_db_backup --dry-run
      
  3. Cron Misconfiguration

    • Symfony’s cron requires a web server. For CLI-only, use system cron:
      0 2 * * * php /path/to/bin/console backup:run my_db_backup >> /dev/null 2>&1
      
  4. Large Backups

    • S3/Rackspace: Enable multipart uploads for files >100MB.
    • Dropbox: Use chunked uploads to avoid timeouts.

Debugging

  • Verbose Output:
    php bin/console backup:run my_db_backup -v
    
  • Log Backups: Enable in config/packages/backup_manager.yaml:
    logging: true
    log_file: "%kernel.logs_dir%/backup.log"
    

Extension Points

  1. Custom Storage Adapters Implement BackupManager\Storage\StorageInterface:

    class GoogleCloudStorage implements StorageInterface
    {
        public function upload($filePath, $remotePath) { ... }
        public function download($remotePath, $localPath) { ... }
    }
    

    Register in config/packages/backup_manager.yaml:

    storage:
        google_cloud:
            adapter: App\Storage\GoogleCloudStorage
            config: { ... }
    
  2. Pre/Post Hooks Use events (backup.pre, backup.post) to add logic:

    jobs:
        my_job:
            type: db
            listeners:
                pre: [App\Listener\PreBackupListener]
                post: [App\Listener\PostBackupListener]
    
  3. Compression Enable gzip for large backups:

    options:
        compression: gzip
        compression_level: 9
    

Config Quirks

  • Default Values: The bundle provides sensible defaults (e.g., local storage to var/backups).
  • Override Globally: Use %kernel.project_dir% for dynamic paths:
    storage:
        local:
            directory: "%kernel.project_dir%/custom/backups"
    
  • Environment-Specific Config: Use when@prod in config/packages/backup_manager.yaml:
    storage:
        s3:
            <<: *default_s3
            when@prod: true
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui