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

Database Dumper Command Bundle Laravel Package

cdwv/database-dumper-command-bundle

Symfony bundle adding a console command to create database backups/dumps. Install via Composer, register the bundle, then run app/console cdwv:database:dump to generate a dump for your configured database.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require cdwv/database-dumper-command-bundle
    

    Register the bundle in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3/2):

    CodeWave\DatabaseDumperCommandBundle\CodeWaveDatabaseDumperCommandBundle::class => ['all' => true],
    
  2. First Use Case Run the dump command to generate a SQL backup:

    php bin/console cdwv:database:dump
    

    Outputs a .sql file in var/dumps/ (default path).

  3. Configuration Check config/packages/cdwv_database_dumper.yaml (Symfony 4+) or app/config/config.yml (Symfony 3/2) for default settings:

    cdwv_database_dumper:
        dump_path: '%kernel.project_dir%/var/dumps'
        dump_filename: 'database_%date%.sql'
        dump_compression: false
    

Implementation Patterns

Workflows

  1. Scheduled Backups Integrate with Symfony’s scheduler (e.g., cron or symfony/process) to run nightly:

    # config/packages/schedule.yaml
    schedule:
        database_backup:
            command: 'cdwv:database:dump'
            cron: '0 2 * * *'  # Daily at 2 AM
    
  2. Custom Dump Filename Logic Extend the command to append environment-specific tags:

    // src/Command/CustomDumpCommand.php
    use Symfony\Component\Console\Command\Command;
    use CodeWave\DatabaseDumperCommandBundle\Command\DatabaseDumpCommand;
    
    class CustomDumpCommand extends DatabaseDumpCommand {
        protected function configure() {
            $this->setName('app:custom-dump');
            $this->setDescription('Dump DB with custom filename');
        }
    
        protected function getDumpFilename() {
            return 'backup_' . date('Y-m-d') . '_' . getenv('APP_ENV') . '.sql';
        }
    }
    
  3. Post-Dump Actions Chain commands using Symfony’s Process or EventDispatcher:

    // src/EventListener/DumpListener.php
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    use CodeWave\DatabaseDumperCommandBundle\Event\DumpEvent;
    
    class DumpListener implements EventSubscriberInterface {
        public static function getSubscribedEvents() {
            return [
                DumpEvent::POST_DUMP => 'onPostDump',
            ];
        }
    
        public function onPostDump(DumpEvent $event) {
            $dumpPath = $event->getDumpPath();
            // Upload to S3, notify Slack, etc.
        }
    }
    

Integration Tips

  • Laravel Adaptation Use Symfony’s Console/Kernel as a bridge:

    // bootstrap/app.php (Laravel)
    $kernel = new Symfony\Component\HttpKernel\Kernel(
        'dev',
        false
    );
    $kernel->boot();
    $command = new \CodeWave\DatabaseDumperCommandBundle\Command\DatabaseDumpCommand();
    $command->run(new Symfony\Component\Console\Input\ArrayInput([]), new Symfony\Component\Console\Output\ConsoleOutput());
    
  • Environment-Specific Paths Override dump_path in .env:

    DUMP_PATH=/backups/production
    

    Then update the config:

    dump_path: '%env(DUMP_PATH)%'
    

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony Version

    • The package targets Symfony 2/3 (last release 2017). For Symfony 4/5/6:
  2. No Compression by Default Enable gzip in config to reduce file size:

    dump_compression: true
    
  3. Permission Issues Ensure var/dumps/ is writable:

    mkdir -p var/dumps && chmod -R 775 var/dumps
    
  4. Large Database Dumps

    • OOM Errors: Use --quick flag in mysqldump (if supported) or split dumps:
      dump_additional_options: '--quick --single-transaction'
      
    • Timeouts: Increase PHP max_execution_time or run via CLI with nohup.

Debugging

  • Verify Dump Path Check if the path exists and is writable:

    // Debug in a command
    $this->getHelper('dialog')->ask('Dump path exists?', $this->getDumpPath());
    
  • Log Dump Events Enable Symfony’s profiler or add logging:

    # config/packages/monolog.yaml
    handlers:
        dump:
            type: stream
            path: var/log/dump.log
            level: debug
    

Extension Points

  1. Custom Dump Format Override the dump() method to use pg_dump (PostgreSQL) or other tools:

    protected function dump() {
        $process = new Process(['pg_dump', '-U', $this->getDbUser(), $this->getDbName()]);
        $process->run();
        file_put_contents($this->getDumpPath(), $process->getOutput());
    }
    
  2. Pre/Post-Dump Hooks Use Symfony’s EventDispatcher to trigger actions:

    // src/EventSubscriber/DumpSubscriber.php
    use CodeWave\DatabaseDumperCommandBundle\Event\DumpEvent;
    
    class DumpSubscriber implements EventSubscriberInterface {
        public static function getSubscribedEvents() {
            return [
                DumpEvent::PRE_DUMP => 'preDump',
                DumpEvent::POST_DUMP => 'postDump',
            ];
        }
    
        public function preDump(DumpEvent $event) {
            // Validate DB connection, send notification, etc.
        }
    }
    
  3. Remote Storage Extend the bundle to upload dumps to S3/Backblaze:

    use Aws\S3\S3Client;
    
    class S3DumpCommand extends DatabaseDumpCommand {
        protected function postDump() {
            $s3 = new S3Client(['version' => 'latest']);
            $s3->putObject([
                'Bucket' => 'my-backups',
                'Key'    => 'dumps/' . basename($this->getDumpPath()),
                'Body'   => file_get_contents($this->getDumpPath()),
            ]);
        }
    }
    

Config Quirks

  • Date Format in Filenames Customize dump_filename to avoid collisions:
    dump_filename: 'backup_%Y-%m-%d_%H-%M-%S.sql'
    
  • Database-Specific Options Pass mysqldump flags via dump_additional_options:
    dump_additional_options: '--no-tablespaces --skip-comments'
    
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.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
headercat/phpstan-extension-ide-helper
yosymfony/parser-utils
innmind/black-box
babenkoivan/elastic-migrations
babenkoivan/elastic-adapter
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle