PHPackages                             bushbaby/flysystem-mysql-backup - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bushbaby/flysystem-mysql-backup

AbandonedArchivedLibrary

bushbaby/flysystem-mysql-backup
===============================

Utility to dump a MySql Database to an 'Flysystem' filesystem

0.4.0(9y ago)0890MITPHPPHP ^7.1

Since Jan 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/bushbaby/BsbFlysystemMysqlBackup)[ Packagist](https://packagist.org/packages/bushbaby/flysystem-mysql-backup)[ Docs](https://github.com/bushbaby/BsbFlysystemMysqlBackup)[ RSS](/packages/bushbaby-flysystem-mysql-backup/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (6)Used By (0)

BsbFlysystemMysqlBackup
=======================

[](#bsbflysystemmysqlbackup)

A small library capable of creating and persisting a Mysql dump into a Flysystem filesystem.

Dependancies;

- [Mysqldump](https://github.com/ifsnop/mysqldump-php) to create a mysql dump
- [Flysystem](https://github.com/league/flysystem) to persist the dump

Compatible with [container-interop/container-interop](https://github.com/container-interop/container-interop) but completely optional.

No wiring is provided as code but I do provide some example configuration. Factories are provided for needed services but you must write a factory for a Flysystem service (see provided example).

Installation
------------

[](#installation)

```
composer require "bushbaby/flysystem-mysql-backup"

```

Usage
-----

[](#usage)

### Programaticly

[](#programaticly)

```
// 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();

```

### Factories (ContainerInterface)

[](#factories-containerinterface)

If you choose to use the Factories to instanciate the service a `config` service is expected to be registered within the Container. That service should contain an `bsb_flysystem_mysql_backup` top level entry with the following keys.

- connection
- storage
- mysql\_dump

The `connection` key must be an array with doctrine connection parameters

```
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'
            ],
        ],
    ],
];

```

or a doctrine connection name.

```
return [
    'bsb_flysystem_mysql_backup' => [
        'connection' => 'orm_default',
    ],
];

```

When you use a doctrine connection name it is assumed an implementation of `Doctrine\Common\Persistence\ManagerRegistry` is registered within the Container. That service is used to retrieve the named connection.

I use this [one](https://github.com/bushbaby/BsbDoctrineManagerRegistryServiceManager).

### Storage options

[](#storage-options)

The `storage` key must be an array containing

```
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 options

[](#mysqldump-options)

The `mysql_dumper` must be an array see [Mysqldump's dump settings](https://github.com/ifsnop/mysqldump-php#dump-settings) for details.

```
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,
        ],
    ],
];

```

### A Factory for a Flysystem filesystem

[](#a-factory-for-a-flysystem-filesystem)

```
