sourcebroker / database-backup
2.0.0
2019-07-04 10:06 UTC
Requires
- dragonmantank/cron-expression: ^2.0
- symfony/config: ^4.0
- symfony/console: ^4.0
- symfony/dependency-injection: ^4.0
- symfony/dotenv: ^4.0
- symfony/finder: ^4.0
- symfony/property-access: ^4.0
- symfony/yaml: ^4.0
Requires (Dev)
- symfony/var-dumper: ^4.0
- vierbergenlars/php-semver: ^3.0
- webcreate/vcs: ^1.2
This package is auto-updated.
Last update: 2024-09-08 20:23:53 UTC
README
它做什么?
此包允许进行数据库备份。强烈强调合理的默认设置,但同时也允许调整每个可能的设置。
特性
- 支持多组配置。
- 类似于Cron的方式设置数据库备份程序应该运行的时间。
- 检测使用数据库的应用程序,忽略不重要的表(如缓存表)。检测到的应用程序数据库的黑白名单。
- 数据库黑白名单。
- 准备支持不同的存储(目前只支持“本地”存储)。
- 按需模式 - 只有在需要时才执行。
安装
composer require sourcebroker/database-backup
使用
创建示例配置命令
php bin/backup db:default-configuration
描述
--dry-run
Perform action without saving any data. This option is for testing purpose.
备份数据库命令
php bin/backup db:dump [--dry-run] [--] <yaml config>
描述
--dry-run Perform action without saving any data. This option is for testing purpose. < yaml config > Configuration file containing backup tasks.
最简单的使用示例
php bin/backup db:dump config.yaml
最简单的config.yaml。下面的配置将在凌晨1点进行备份,保留2天。
configs: dayilyAt1am: cron: howMany: 2 pattern: "0 1 * * *"
您可以在一个文件中添加更多配置。下面的配置将在凌晨1点进行备份,保留7天,并在每个小时的第15分钟进行备份,保留最后5小时。
configs: dayily: cron: howMany: 7 pattern: "0 1 * * *" hourly: cron: howMany: 5 pattern: "15 * * * *"
配置
有关配置的更多信息。在./sample目录中提供Magento和TYPO3的示例配置。
默认配置(内置)
defaults: tmpDir: ".tmp" # temporary files directory flagDir: ".flag" # flag files directory defaultsFile: "~/.my.cnf" # path to file with authentication data binaryDbCommand: "" # mysql binary path (replaced with `which mysql` if empty) binaryDbExport: "" # mysqldump binary path (replaced with `which mysqldump` if empty) binaryPacker: "" # zip binary path (replaced with `which zip` if empty) databaseAccess: # database access branch type: "default" # authentication type (described below) path: "" # path to file with db authentication data data: # authentication data (direct) user: "" # username password: "" # password port: "" # database port host: "" # database port storage: # storage description branch local: # local storage path: ".dump" # path to local directory where backuper will store packs application: # application autodetection branch typo3: # app name tables: # tables description detection: # detect application depending on existance of tables - "tt_content" whitelist: # include those tables in backup - ".*" blacklist: # exclude those tables from backup - "cf_.*" whitelistPresets: [] # not implemented yet blacklistPresets: [] # not implemented yet magento: tables: detection: - "core_config_data" whitelist: - ".*" blacklist: - "/^cache.*$/" - "/^log_.*$/" whitelistPresets: [], blacklistPresets: [] tables: {} # tables branch (check "tables configuration" section below) databases: # databases branch whitelist: # include those tables in backup - ".*" blacklist: # exclude those tables from backup - "information_schema" whitelistPresets: [] # not implemented yet blacklistPresets: [] # not implemented yet presets: [] # not implemented yet
用户配置(yaml文件)
# Defaults branch # Here you can specify values defaults: <any branch> # any branch from default configuration may be overriden here # Tasks configuration branch # You can define multiple backup tasks. Each one may be executed on command run, # depending on cron pattern and 'onDemand' flag configs: catalogOnDemand: # task name cron: # CRON description howMany: 10 # how many backups should be stored pattern: "* * * * *" # CRON time pattern onDemand: true # set if this mode should be executed only on demand (optional) <any branch> # any branch from defaults may be overriden here
数据库认证
有4种可用的认证模式
- 'default' - 使用数据库访问级别上提供的配置文件(MySQL配置格式)作为'path'(默认~/.my.cnf)
- 'env' - 从环境中读取认证数据(可以使用.env文件)
- 'php' - 从PHP文件中读取
- 'xml' - 从XML文件中读取
表配置
tables: _default_: # default tables configuration (for all databases) whitelist: # include those tables - ".*" # regular expression blacklist: # exclude those tables - "cache_.*" <database name>: # database level branch (override _default_ configuration) whitelist: # include those tables (from given database) - "important_.*" blacklist: # exclude those tables (from given database) - "cache_.*" - "log_.*"
如果任务设置了onDemand模式,则它将仅条件性地执行。该任务只有在标志目录(在'flagDir'中定义)中创建了标志文件时才会执行(文件名是任务名的小写 - 因此对于catalogOnDemand任务,它将是catalogondemand)。
按需模式
如果任务设置了onDemand模式,则它将仅条件性地执行。该任务只有在CRON时间模式满足且在标志目录(在'flagDir'中定义)中创建了标志文件时才会执行(文件名是任务名的小写 - 因此对于catalogOnDemand任务,它将是catalogondemand)。
使用案例:在放置新订单后立即备份订单表。修改您的应用程序,使其在定义的目录中创建标志文件。