symandy / database-backup-bundle

用于处理数据库备份的 Symfony 扩展包

安装: 496

依赖项: 1

建议者: 0

安全: 0

星标: 5

关注者: 1

分支: 2

开放问题: 2

类型:symfony-bundle

v0.4.0 2023-04-19 14:05 UTC

This package is auto-updated.

Last update: 2024-09-20 12:07:53 UTC


README

DatabaseBackupBundle 是一个用于管理数据库备份的 Symfony 扩展包。

Build

安装

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 的 发布页面 中查看版本之间的所有更改。