symandy / database-backup-bundle
用于处理数据库备份的 Symfony 扩展包
v0.4.0
2023-04-19 14:05 UTC
Requires
- php: >=8.1
- nyholm/dsn: ^2.0
- symfony/config: ^6.0
- symfony/dependency-injection: ^6.0
- symfony/http-kernel: ^6.0
- symfony/process: ^6.0
- symfony/property-access: ^6.0
- symfony/serializer: ^6.0
Requires (Dev)
- doctrine/orm: ^2.11
- friendsofphp/php-cs-fixer: ^3.16
- phpstan/phpstan: ^1.5
- phpunit/phpunit: ^9.5
- symfony/console: ^6.0
- symfony/dotenv: ^6.0
- symfony/framework-bundle: ^6.0
- symfony/phpunit-bridge: ^6.0
- symfony/yaml: ^6.0
- webmozart/assert: ^1.11
README
DatabaseBackupBundle 是一个用于管理数据库备份的 Symfony 扩展包。
安装
composer require symandy/database-backup-bundle
如果 Symfony Flex 还未启用扩展包(将在 symfony/recipes-contrib 提交 PR),请在 config/bundles.php
中添加以下行。
<?php return [ ... Symandy\DatabaseBackupBundle\SymandyDatabaseBackupBundle::class => ['all' => true], ... ];
配置
YAML 配置
如前所述,如果 Symfony Flex 未启用,请将以下文件(symandy_database_backup.yaml
)添加到 config/packages
目录。
基本配置
如果只是为了备份当前项目的数据库,请使用基本配置文件。
symandy_database_backup: backups: app: connection: url: "%env(DATABASE_URL)%" strategy: max_files: 5 backup_directory: "%kernel.project_dir%/backups"
高级用法
symandy_database_backup: backups: foo: connection: # driver: !php/const \Symandy\DatabaseBackupBundle\Model\ConnectionDriver::MySQL driver: mysql # Usage of environment variables as parameters is recommended for connections configuration configuration: user: "%app.foo_db_user%" password: "%app.foo_db_password%" host: 127.0.0.1 # Already the default value, don't need to be added port: 3306 # Already the default value, don't need to be added databases: [foo, bar, baz] # Will only back up these databases strategy: max_files: 5 # Number of files kept after a backup (per database) # backup_directory: "/var/www/backups" # The directory must be created and must have the right permissions backup_directory: "%kernel.project_dir%/backups" # backup_directory: ~ # The current directory will be used if no value is passed date_format: 'Y-m-d-His' # The date format to use in backup files (default: 'Y-m-d') bar: # Use Doctrine database url env parameter connection: url: "%env(DATABASE_URL)%" # url key will ALWAYS override array configuration configuration: user: john # Overridden by url
驱动程序
目前仅提供 mysql
驱动程序。
用法
配置备份后,您只需运行以下命令来生成数据库备份文件
php bin/console symandy:databases:backup
它将按数据库生成一个文件,格式为 <backup_name>-<database>-<date_format>.sql
。
变更日志
您可以在 CHANGELOG.md 或 GitHub 的 发布页面 中查看版本之间的所有更改。