raffaelecarelle / symfony-backup-bundle
Symfony bundle for database and filesystem backup/restore management
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.1
- dragonmantank/cron-expression: ^3.3
- symfony/config: ^6.0|^7.0
- symfony/console: ^6.0|^7.0
- symfony/dependency-injection: ^6.0|^7.0
- symfony/event-dispatcher: ^6.0|^7.0
- symfony/framework-bundle: ^6.0|^7.0
- symfony/http-foundation: ^6.0|^7.0
- symfony/http-kernel: ^6.0|^7.0
- symfony/messenger: ^7.3
- symfony/process: ^6.0|^7.0
- symfony/scheduler: ^7.3
- symfony/yaml: ^6.0|^7.0
Requires (Dev)
- ext-pdo: *
- doctrine/doctrine-bundle: ^2.0
- friendsofphp/php-cs-fixer: ^3.85
- phpunit/phpunit: ^9.5
- rector/rector: ^2.1
- symfony/browser-kit: ^6.0|^7.0
- symfony/css-selector: ^6.0|^7.0
- symfony/phpunit-bridge: ^6.0|^7.0
- symfony/twig-bundle: ^6.0|^7.0
- symfony/web-profiler-bundle: ^6.0|^7.0
Suggests
- aws/aws-sdk-php: For S3 storage adapter
- doctrine/doctrine-bundle: For database backup support
- google/cloud-storage: For Google Cloud storage adapter
This package is auto-updated.
Last update: 2025-07-31 09:38:16 UTC
README
A Symfony bundle for database and filesystem backup/restore management.
Overview
The Symfony Backup Bundle provides a complete and configurable system for automatic and manual backups of databases and filesystems, with native integration in the Symfony Profiler for development operations.
Features
- Database backup and restore (MySQL, PostgreSQL, SQLite, SQL Server)
- Filesystem backup and restore
- Multiple storage adapters (Local, S3, Google Cloud)
- Compression support (Gzip, Zip)
- Scheduled backups
- Event system for backup/restore operations
- Symfony Profiler integration
- Command-line interface
Installation
composer require raffaelecarelle/symfony-backup-bundle
Configuration
Create a configuration file at config/packages/backup.yaml
:
pro_backup: default_storage: 'local' storage: local: adapter: 'local' options: path: '%kernel.project_dir%/var/backups' permissions: 0755 s3: adapter: 's3' options: bucket: 'my-app-backups' region: 'eu-west-1' credentials: key: '%env(AWS_ACCESS_KEY_ID)%' secret: '%env(AWS_SECRET_ACCESS_KEY)%' google_cloud: adapter: 'google_cloud' options: bucket: 'my-app-backups' project_id: '%env(GOOGLE_CLOUD_PROJECT_ID)%' key_file: '%env(GOOGLE_CLOUD_KEY_FILE)%' database: enabled: true connections: ['default'] # List of Doctrine connections compression: 'gzip' retention_days: 30 exclude_tables: ['cache_items', 'sessions'] options: mysql: single_transaction: true routines: true triggers: true postgresql: format: 'custom' verbose: true filesystem: enabled: false paths: - { path: '%kernel.project_dir%/public/uploads', exclude: ['*.tmp', '*.log'] } - { path: '%kernel.project_dir%/config', exclude: ['secrets/'] } compression: 'zip' retention_days: 7 schedule: database: frequency: 'daily' # daily, weekly, monthly, cron expression time: '02:00' filesystem: frequency: 'weekly' time: '03:00' notifications: on_success: false on_failure: true channels: ['email'] # email, slack, webhook
Usage
Command Line
Create a database backup:
php bin/console backup:create --type=database
Restore a backup:
php bin/console backup:restore <backup-id>
List available backups:
php bin/console backup:list
Programmatic Usage
use Symfony\Component\Backup\Model\BackupConfiguration; use Symfony\Component\Backup\Manager\BackupManager; // Create a backup $config = new BackupConfiguration(); $config->setType('database'); $config->setName('my_backup'); $backupManager = $container->get(BackupManager::class); $result = $backupManager->backup($config); if ($result->isSuccess()) { echo "Backup created: " . $result->getFilePath(); } else { echo "Backup failed: " . $result->getError(); } // Restore a backup $backupId = 'backup_123'; $success = $backupManager->restore($backupId); if ($success) { echo "Backup restored successfully"; } else { echo "Restore failed"; }
Events
The bundle dispatches the following events:
backup.pre_backup
: Before a backup operationbackup.post_backup
: After a successful backup operationbackup.failed
: When a backup operation failsbackup.pre_restore
: Before a restore operationbackup.post_restore
: After a successful restore operationbackup.restore_failed
: When a restore operation fails
Testing
Run the PHPUnit tests:
vendor/bin/phpunit
License
This bundle is released under the MIT License.