Installation
composer require edemy/backupbundle
Ensure eDemyFramework is installed (this bundle is framework-specific).
Configuration
Add the bundle to config/bundles.php:
return [
// ...
Edemy\BackupBundle\EdemyBackupBundle::class => ['all' => true],
];
Basic Usage
Define a backup job in config/backup.php:
jobs:
default:
type: 'filesystem'
path: '%kernel.project_dir%/var/backups'
files:
- '%kernel.project_dir%/app'
- '%kernel.project_dir%/var/logs'
First Run Trigger a backup via CLI:
php bin/console edemy:backup:run default
config/backup.php (primary config file).bin/console edemy:backup: (list available commands).Edemy\BackupBundle\Event\BackupEvents (for custom logic).Scheduled Backups
Use Symfony’s CronBundle or Laravel Scheduler (if hybrid) to automate:
# config/packages/cron.yaml
cron:
jobs:
daily_backup:
command: 'edemy:backup:run default'
schedule: '0 2 * * *'
Conditional Backups
Extend the BackupJob class to add logic (e.g., skip if DB is locked):
// src/Backup/CustomJob.php
namespace App\Backup;
use Edemy\BackupBundle\Job\BackupJob;
class CustomJob extends BackupJob {
protected function shouldRun(): bool {
return !\DB::connection()->getPdo()->inTransaction();
}
}
Multi-Environment Backups
Override path in backup.php per environment:
# config/backup.php (prod)
jobs:
prod:
path: '/mnt/backups/prod'
Post-Backup Actions
Listen to BackupEvents::POST_BACKUP to notify Slack/email:
// src/EventListener/BackupListener.php
namespace App\EventListener;
use Edemy\BackupBundle\Event\BackupEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BackupListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
BackupEvents::POST_BACKUP => 'onBackupComplete',
];
}
public function onBackupComplete() {
// Send notification
}
}
symfony/console bridge if mixing frameworks:
use Symfony\Component\Console\Application;
$app = new Application();
$app->add(new \Edemy\BackupBundle\Command\BackupCommand());
Edemy\BackupBundle\Storage\StorageInterface for S3/Cloud storage.monolog via BackupEvents::PRE_BACKUP.Framework Lock-in
Artisan or use spatie/laravel-backup.Permission Issues
path in backup.php is writable by the web server:
chmod -R 775 %kernel.project_dir%/var/backups
/var/backups/app) to avoid symlink confusion.Missing Events
PRE_BACKUP event in early versions; patch or extend:
// src/Event/PreBackupEvent.php
namespace App\Event;
use Edemy\BackupBundle\Event\BackupEvents;
class PreBackupEvent extends \Symfony\Contracts\EventDispatcher\Event {}
Database Backups
mysqldump in files or integrate ocramius/package-versions for PHP dependency backups.dry_run: true to backup.php to test without writing files.-vvv for detailed logs:
php bin/console edemy:backup:run default -vvv
StorageInterface implementations for custom logic quirks.Custom Storage
Implement Edemy\BackupBundle\Storage\StorageInterface for S3/Google Drive:
class S3Storage implements StorageInterface {
public function save(string $path, string $content): bool {
// Use AWS SDK
}
}
Job Factories
Override Edemy\BackupBundle\Factory\BackupJobFactory to add pre/post hooks.
Notification Channels
Extend Edemy\BackupBundle\Notifier\NotifierInterface for custom alerts (e.g., Telegram).
.backupignore (like .gitignore) in the backup root.compression: true to backup.php for .zip outputs.cron + find to auto-delete old backups:
find /var/backups -type f -mtime +30 -delete
How can I help you explore Laravel packages today?