小熊猫 / flysystem-mysql-backup
此包已被弃用且不再维护。未建议替代包。
将MySql数据库导出到'Flysystem'文件系统的实用工具
0.4.0
2017-04-15 13:19 UTC
Requires
- php: ^7.1
- doctrine/dbal: ^2.5
- ifsnop/mysqldump-php: ^2.1
- league/flysystem: ^1.0
- psr/container: ^1.0
- zendframework/zend-stdlib: ^2.7 || ^3.0
Requires (Dev)
- bushbaby/flysystem: ^2.0
- plhw/hf-cs-fixer-config: ^1.0
Suggests
- bushbaby/doctrine-managerregistry-servicemanager: An implementation of Doctrine's ManagerRegistry for the ZendFramework ServiceManager
- bushbaby/flysystem: Zend Framework 2 module bridge for flysystem filesystem
README
一个小型库,能够创建并持久化Mysql导出到Flysystem文件系统。
依赖关系;
与 container-interop/container-interop 兼容,但完全可选。
未提供代码化的连接,但我提供了一些示例配置。提供所需服务的工厂,但您必须编写一个Flysystem服务的工厂(参见提供的示例)。
安装
composer require "bushbaby/flysystem-mysql-backup"
用法
编程式
// setup dumper
$dumpOptions = new MysqlDumperOptions();
$dumper = new MysqlDumperService($dsn, $user, $password, $dumpOptions);
// setup storage
$filesystem = new Filesystem(new SomeFlystemAdapter());
// setup backup service
$storageOptions = new StorageOptions();
$backup = new MysqlBackupService($dumperService, $filesystem, $storageOptions, $dumpSettings);
// invoke
$backup->doBackup();
$backup->pruneStorage();
工厂(ContainerInterface)
如果您选择使用工厂来实例化服务,则容器中应注册一个config
服务。该服务应包含一个bsb_flysystem_mysql_backup
顶级条目,其中包含以下键。
- 连接
- 存储
- mysql导出
连接
键必须是一个包含doctrine连接参数的数组
return [
'bsb_flysystem_mysql_backup' => [
'connection' => [
'host' => 'localhost',
'user' => 'dbuser',
'password' => 'dbpass',
'dbname' => 'dbname',
'charset' => 'utf8',
'driverOptions' => [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
],
],
],
];
或一个doctrine连接名称。
return [
'bsb_flysystem_mysql_backup' => [
'connection' => 'orm_default',
],
];
当您使用doctrine连接名称时,假设容器中注册了Doctrine\Common\Persistence\ManagerRegistry
的实现。该服务用于检索命名连接。
我使用这个实现。
存储选项
存储
键必须是一个包含以下内容的数组
return [
'bsb_flysystem_mysql_backup' => [
'storage' => [
/*
* Container service name of the Flysystem filesystem used to persisted dumps
*
* @since 0.2.0 this may also be the name of a filesystem as it has been registered to the BsbFlysystem Manager
*/
// 'filesystem' => 'Container/Name/Of/FilesystemService',
/*
* Path within the Flysystem filesystem where dumps are persisted
*/
// 'path' => '/',
/*
* Store the basename of the last created backup in this file
* false|string
*/
// 'write_latest' => false,
/*
* Prune backup files from storage after creating a backup
*/
// 'auto_prune' => false,
/*
* Prune backup files from storage when there are more than x files
*
* default 0 (disabled)
*/
// 'prune_max_count' => 0,
/*
* Prune backup files from storage after x seconds
*
* default 0 (disabled)
*/
// 'prune_max_ttl' => 0,
],
],
];
Mysqldump选项
mysql_dumper
必须是一个数组,有关详细信息,请参阅Mysqldump的导出设置。
return [
'bsb_flysystem_mysql_backup' => [
'mysql_dumper' => [
'include_tables' => [],
'exclude_tables' => [],
'compress' => Mysqldump::GZIP,
'no_data' => false,
'add_drop_table' => true,
'single_transaction' => true,
'lock_tables' => true,
'add_locks' => true,
'extended_insert' => false,
'complete_insert' => false,
'disable_keys' => true,
'where' => '',
'no_create_info' => false,
'skip_triggers' => false,
'add_drop_trigger' => true,
'routines' => false,
'hex_blob' => true,
'databases' => false,
'add_drop_database' => false,
'skip_tz_utc' => false,
'no_autocommit' => true,
'default_character_set' => Mysqldump::UTF8,
'skip_comments' => false,
'skip_dump_date' => false,
],
],
];
Flysystem文件系统的工厂
<?php
namespace MyNamespace\Container;
use Aws\S3\S3Client;
use Interop\Container\ContainerInterface;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
use Zend\Stdlib\ArrayUtils;
class FilesystemFactory
{
/**
* @param ContainerInterface $container
* @return Filesystem
*/
public function __invoke(ContainerInterface $container)
{
$config = $container->get('config')['mysql_backup_to_s3'];
$client = new S3Client([
'credentials' => $config['credentials'],
'region' => $config['region'],
// frankfurt
'version' => $config['version'],
// or latest, but not recommended in production
]);
$adapter = new AwsS3Adapter($client, $config['bucket']);
$filesystem = new Filesystem($adapter);
return $filesystem;
}
}