district09/备份管理器

一个与框架无关的数据库备份管理器,具有用户定义的程序,并支持S3、Dropbox、FTP、SFTP等,并提供流行框架的驱动程序。

4.0.2 2024-03-28 10:51 UTC

This package is auto-updated.

Last update: 2024-08-28 11:38:01 UTC


README

Latest Stable Version License Total Downloads

此软件包提供了一种框架无关的数据库备份管理器,用于将数据库导出到S3、Dropbox、FTP、SFTP和Rackspace Cloud,以及从这些位置恢复数据库。

  • 使用版本2+适用于PHP 7.3及以上
  • 使用版本1适用于PHP 7.2以下

观看视频教程,了解Laravel驱动程序的实际操作,以便了解可以做什么。

目录

快速入门

配置您的数据库。

// config/database.php
'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.
    // This is useful on transactional databases like InnoDB.
    // https://dev.mysqlserver.cn/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
    'singleTransaction' => false,
    // Do not dump the given tables
    // Set only table names, without database name
    // Example: ['table1', 'table2']
    // https://dev.mysqlserver.cn/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',
],

配置您的文件系统。

// config/storage.php
'local' => [
    'type' => 'Local',
    'root' => '/path/to/working/directory',
],
's3' => [
    'type' => 'AwsS3',
    'key'    => '',
    'secret' => '',
    'region' => 'us-east-1',
    'version' => 'latest',
    'bucket' => '',
    'root'   => '',
    'use_path_style_endpoint' => false,
],
'b2' => [
    'type' => 'B2',
    'key'    => '',
    'accountId' => '',
    'bucket' => '',
],
'gcs' => [
    'type' => 'Gcs',
    'key'    => '',
    'secret' => '',
    'version' => 'latest',
    'bucket' => '',
    'root'   => '',
],
'rackspace' => [
    'type' => 'Rackspace',
    'username' => '',
    'key' => '',
    'container' => '',
    'zone' => '',
    'root' => '',
],
'dropbox' => [
    'type' => 'DropboxV2',
    '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' => '',
],
'flysystem' => [
    'type' => 'Flysystem',
    'name' => 's3_backup',
    //'prefix' => 'upload',
],
'doSpaces' => [
    'type' => 'AwsS3',
    'key' => '',
    'secret' => '',
    'region' => '',
    'bucket' => '',
    'root' => '',
    'endpoint' => '',
    'use_path_style_endpoint' => false,
],
'webdav' => [
    'type' => 'Webdav',
    'baseUri' => 'http://myserver.com',
    'userName' => '',
    'password' => '',
    'prefix' => '',
],

备份到/从任何配置的数据库恢复。

将开发数据库备份到 Amazon S3。最终,当使用 gzip 压缩时,S3备份路径将是 test/backup.sql.gz

use District09\BackupManager\Filesystems\Destination;

$manager = require 'bootstrap.php';
$manager->makeBackup()->run('development', [new Destination('s3', 'test/backup.sql')], 'gzip');

备份到/从任何配置的文件系统恢复。

Amazon S3 将数据库文件 test/backup.sql.gz 恢复到 开发 数据库。

$manager = require 'bootstrap.php';
$manager->makeRestore()->run('s3', 'test/backup.sql.gz', 'development', 'gzip');

此软件包不允许您从一个数据库类型备份并恢复到另一个类型。MySQL转储与PostgreSQL不兼容。

要求

  • PHP 5.5
  • MySQL支持需要 mysqldumpmysql 命令行二进制文件
  • PostgreSQL支持需要 pg_dumppsql 命令行二进制文件
  • Gzip支持需要 gzipgunzip 命令行二进制文件

安装

Composer

运行以下命令通过Composer包含此软件包

composer require backup-manager/backup-manager

然后,您需要选择您想要使用的适配器的适当软件包。

# to support s3
composer require league/flysystem-aws-s3-v3

# to support b2
composer require mhetreramesh/flysystem-backblaze

# to support google cs
composer require league/flysystem-aws-s3-v2

# to install the preferred dropbox v2 driver
composer required spatie/flysystem-dropbox

# to install legacy dropbox v2 driver
composer require srmklive/flysystem-dropbox-v2

# to support rackspace
composer require league/flysystem-rackspace

# to support sftp
composer require league/flysystem-sftp

# to support webdav (supported by owncloud nad many other)
composer require league/flysystem-webdav

使用

安装完成后,必须进行引导(初始配置)才能使用。

我们在此提供了原生PHP示例 此处

所需引导可在 此处 找到。

贡献指南

我们建议使用此软件包附带的开发和贡献vagrant配置。只需安装VirtualBox、Vagrant和Ansible,然后在根目录中运行 vagrant up。将为您构建和启动一个专门为包的开发而设计的虚拟机。

在贡献时,请考虑以下指南

  • 代码风格是PSR-2
    • 接口不应以 Interface 结尾,特质不应以 Trait 结尾。
  • 所有方法和类都必须包含文档块。
  • 确保您提交的测试具有至少100%的覆盖率。鉴于项目的简单性,这只是一个合理的做法。
  • 在计划拉取请求以添加新功能时,提出一个 提案 可能是明智的,以确保与项目目标兼容。

维护者

本软件包由Shawn McCool和您维护!

向后兼容性中断

3.0

移除对symfony 2的支持,特别是symfony/process版本小于3.x的支持。

许可协议

本软件包遵循MIT许可证。尽情使用吧。