kematjaya / backup-bundle
2.0
2024-10-28 09:36 UTC
Requires
- doctrine/collections: ^1.6
- doctrine/persistence: ~2.0|^3.0
- spatie/db-dumper: ^2.21
- symfony/event-dispatcher: ^5.4|^6.0
- symfony/framework-bundle: ^5.3|^6.0
- symfony/yaml: ^5.3|^6.0
Requires (Dev)
- doctrine/doctrine-bundle: ^2.7
- phpunit/phpunit: ^9.5
- symfony/browser-kit: ^5.3
- symfony/var-dumper: ^5.3
README
- installation
composer require kematjaya/backup-bundle
- setting
## config/packages/backup.yaml
backup:
name: postgresql
location: '%kernel.project_dir%/var/backup'
- usage
php bin/console database:dump
- insert event
// save log to database
namespace App\EventListener;
use App\Repository\BackupRepository;
use Kematjaya\BackupBundle\Event\AfterDumpEvent;
use Kematjaya\BackupBundle\Event\BackupEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Description of BackupEventListener
*
* @author apple
*/
class BackupEventListener implements EventSubscriberInterface
{
private BackupRepository $backupRepository;
public function __construct(BackupRepository $backupRepository)
{
$this->backupRepository = $backupRepository;
}
public static function getSubscribedEvents():array
{
return [
BackupEvents::AFTER_DUMP => "saveLog"
];
}
public function saveLog(AfterDumpEvent $evt):void
{
$this->backupRepository->create($evt->getFileName());
}
}