branlute/backup-manager-symfony
Installation Run:
composer require backup-manager/symfony
The bundle auto-registers via Symfony Flex.
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
First Run Trigger manually via CLI:
php bin/console backup:run my_db_backup
Verify backups appear in var/backups.
config/packages/backup_manager.yaml (default paths, jobs, storage).php bin/console list backup (list available commands).config/packages/backup_manager.yaml under storage (S3, Dropbox, etc.).Defining Jobs
jobs:
daily_db:
type: db
name: "Daily DB Backup"
storage: { type: s3, ... }
options:
db_dsn: "mysql://user:pass@localhost/db"
jobs:
app_files:
type: filesystem
name: "App Files Backup"
storage: { type: dropbox, ... }
options:
source: "%kernel.project_dir%/var"
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)%"
Scheduling
Use Symfony’s cron or a scheduler like Laravel Horizon (via backup:run command in a queue job).
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
}
}
}
artisan alias for commands:
php artisan backup:run my_db_backup
.env (e.g., S3_KEY=...).$this->backupManager->setStorage(new MockStorage());
Storage Permissions
var/backups is writable:
chmod -R 775 var/backups
aws s3 ls).Database Connection Issues
SELECT privileges only.php bin/console backup:run my_db_backup --dry-run
Cron Misconfiguration
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
Large Backups
php bin/console backup:run my_db_backup -v
config/packages/backup_manager.yaml:
logging: true
log_file: "%kernel.logs_dir%/backup.log"
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: { ... }
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]
Compression Enable gzip for large backups:
options:
compression: gzip
compression_level: 9
local storage to var/backups).%kernel.project_dir% for dynamic paths:
storage:
local:
directory: "%kernel.project_dir%/custom/backups"
when@prod in config/packages/backup_manager.yaml:
storage:
s3:
<<: *default_s3
when@prod: true
How can I help you explore Laravel packages today?