davmixcool/php-dbcloud
Composer 安装命令:
composer require davmixcool/php-dbcloud
包简介
Easily backup PostgreSql or MySql database to the cloud
关键字:
README 文档
README
PHP-DBCLOUD is a php library that creates backup of your PostgreSql / MySql database and uploads it to the cloud. It also support restoring of the backedup database from the cloud.
Features
-
Creating backups
- MySQL
- PostgreSQL
-
Compress backups
- gZip
-
Sync backups to other locations
- Amazon s3
- Dropbox
- Google Cloud Storage
- FTP
- SFTP
Requirements
- PHP 5.5
- MySQL support requires
mysqldumpandmysqlcommand-line binaries - PostgreSQL support requires
pg_dumpandpsqlcommand-line binaries - Gzip support requires
gzipandgunzipcommand-line binaries
Steps:
Install
Composer
Run the following to include this via Composer
composer require davmixcool/php-dbcloud
Then, you'll need to select the appropriate packages for the adapters that you want to use.
# to support Amazon s3 composer require league/flysystem-aws-s3-v3 # to support Dropbox (api v1) composer require srmklive/flysystem-dropbox # to support Dropbox (api v2) composer require srmklive/flysystem-dropbox-v2 # to support Google Cloud Storage composer require league/flysystem-aws-s3-v2 # to support Sftp composer require league/flysystem-sftp
Configuration
Configure your databases
//config/database.php return [ 'development' => [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => 'password', 'database' => 'test', // If singleTransaction is set to true, the --single-transcation flag will be set. 'singleTransaction' => false, // Do not dump the given tables // Set only table names, without database name // Example: ['table1', 'table2'] // http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_ignore-table 'ignoreTables' => [], // using ssl to connect to your database - active ssl-support (mysql only): 'ssl'=>false, // add additional options to dump-command (like '--max-allowed-packet') 'extraParams'=>null, ], 'production' => [ 'type' => 'postgresql', 'host' => 'localhost', 'port' => '5432', 'user' => 'postgres', 'pass' => 'password', 'database' => 'test', ], ]
Configure your filesystems
// config/storage.php return [ 'local' => [ 'type' => 'Local', 'root' => '/path/to/working/directory', ], 's3' => [ 'type' => 'AwsS3', 'key' => '', 'secret' => '', 'region' => 'us-east-1', 'version' => 'latest', 'bucket' => '', 'root' => '', ], 'gcs' => [ 'type' => 'Gcs', 'key' => '', 'secret' => '', 'version' => 'latest', 'bucket' => '', 'root' => '', ], 'dropbox-v2' => [ 'type' => 'DropboxV2', 'token' => '', 'key' => '', 'secret' => '', 'app' => '', 'root' => '', ], 'dropbox-v1' => [ 'type' => 'DropboxV1', 'token' => '', 'key' => '', 'secret' => '', 'app' => '', 'root' => '', ], 'ftp' => [ 'type' => 'Ftp', 'host' => '', 'username' => '', 'password' => '', 'root' => '', 'port' => 21, 'passive' => true, 'ssl' => true, 'timeout' => 30, ], 'sftp' => [ 'type' => 'Sftp', 'host' => '', 'username' => '', 'password' => '', 'root' => '', 'port' => 21, 'timeout' => 10, 'privateKey' => '', ], ]
Usage
Once installed, the package must be bootstrapped with initial configurations before it can be used.
Bootstrap the package
use PhpDbCloud\Config\Config; use PhpDbCloud\Filesystems; use PhpDbCloud\Databases; use PhpDbCloud\Compressors; use PhpDbCloud\Sync; // build providers $filesystems = new Filesystems\FilesystemProvider(Config::fromPhpFile('config/storage.php')); $filesystems->add(new Filesystems\Awss3Filesystem); $filesystems->add(new Filesystems\GcsFilesystem); $filesystems->add(new Filesystems\DropboxV1Filesystem); $filesystems->add(new Filesystems\DropboxV2Filesystem); $filesystems->add(new Filesystems\FtpFilesystem); $filesystems->add(new Filesystems\LocalFilesystem); $filesystems->add(new Filesystems\SftpFilesystem); $databases = new Databases\DatabaseProvider(Config::fromPhpFile('config/database.php')); $databases->add(new Databases\MysqlDatabase); $databases->add(new Databases\PostgresqlDatabase); $compressors = new Compressors\CompressorProvider; $compressors->add(new Compressors\GzipCompressor); $compressors->add(new Compressors\NullCompressor); // build sync return new Sync($filesystems, $databases, $compressors);
Backup to configured database
Backup the development database to Dropbox Api V2. The Dropbox backup path will be test/backup.sql.gz in the end, when gzip is done with it.
use PhpDbCloud\Filesystems\Destination; $sync = require 'bootstrap.php'; $sync->makeBackup()->run('development', [new Destination('dropbox-v2', 'test/backup.sql')], 'gzip');
Restore from configured database
Restore the database file test/backup.sql.gz from Dropbox Api V2 to the development database.
$sync = require 'bootstrap.php'; $sync->makeRestore()->run('dropbox-v2', 'test/backup.sql.gz', 'development', 'gzip');
This package does not allow you to backup from one database type and restore to another. A MySQL dump is not compatible with PostgreSQL.
Example
See Example here.
Maintainers
This package is maintained by David Oti and you!
License
This package is licensed under the MIT license.
davmixcool/php-dbcloud 适用场景与选型建议
davmixcool/php-dbcloud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.52k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2018 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「sql」 「db」 「mysql」 「postgresql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 davmixcool/php-dbcloud 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 davmixcool/php-dbcloud 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 davmixcool/php-dbcloud 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Query filtering in your frontend
A PSR-7 compatible library for making CRUD API endpoints
Database/ORM-agnostic query construction helper
统计信息
- 总下载量: 1.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-23