定制 coderatio/simple-backup 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

coderatio/simple-backup

Composer 安装命令:

composer require coderatio/simple-backup

包简介

A simple mysql database backup library for php.

README 文档

README


A simple mysql database backup library for php. This library helps you backup your mysql database to a directory in your project or download it to your machine.

The library also allows you import or restore a database without stress. Follow the instructions below to get started.

Installation

Open your terminal or command prompt and type the below command:

composer require coderatio/simple-backup

New in version 1.0.1

  1. You can now chain static ::start() on `SimpleBackup class.
  2. This version includes fluent chaining of database settings.
  3. Added ->includeOnly(array $tables) which allows you to export data for only tables mentioned in $tables variable.
  4. Added ->excludeOnly(array $tables) which removes the inclussion of tables mentioned in $tables variable during export.

(v1.0.1) Exporting specific tables only

  SimpleBackup::start()
    ->setDbName('db_name')
    ->setDbUser('db_username')
    ->setDbPassword('db_password')
    ->includeOnly(['carts', 'houses', 'categories'])
    ->then()->storeAfterExportTo('backups')
    ->then()->getResponse();

(v1.0.1) Excluding specific tables only

  SimpleBackup::start()
    ->setDbName('db_name')
    ->setDbUser('db_username')
    ->setDbPassword('db_password')
    ->excludeOnly(['users', 'posts'])
    ->then()->storeAfterExportTo('backups')
    ->then()->getResponse();

Exporting

The export can be done in two ways.

  1. Store in a directory
  2. Download to your machine

1-- Store in a directory

To store the export in a directory, do this:

require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
  ->storeAfterExportTo('pathtostore', 'file_name (optional)');

To get the stored file name, you can echo it out like this:

echo $simpleBackup->getExportedName();

You can also get the reponse by doing this:

/**
* @return object
**/
var_dump($simpleBackup->getResponse());

2-- Download

To download the export to your machine, do this:

require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
  ->downloadAfterExport($file_name (optional));

If $file_name isn't provided, a random name will be generated for the download.

Adding where clauses to tables

To add where clauses as you would do on SQL, you can do this before exporting:

Note: $tables variable must be an associative array e.g

$tables = [
  'users' => 'is_active = true'
];
$simpleBackup->setTableConditions(array $tables);

Setting rows limit on tables

To limit how many rows to be included in your backup for a table, do this before exporting:

Note: Just like adding where clauses, the $tables variable here must be an associative array. e.g

$tables = [
  'users' => 50,
  'posts' => 50
]
$simpleBackup->setTableLimitsOn(array $tables);

Importing

This package makes importing or restoring your mysql database easy. To import your database, do this:

require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host (optional)']])
    ->importFrom('pathtosql_file or sql_contents');

/**
* You can then dump the response like this. 
*
* @return object
**/
var_dump($simpleBackup->getResponse());

Note: You can provide sql statements as the parameter. You may also overwrite the database configuration by passing it as second parameter to the importFrom(). e.g importFrom(pathtosql_file, array $db_config);.

Todo

  1. Add a scheduler method to use with cron
  2. Store backup in Dropbox, Google Drive.
  3. Send backup to emails

Contribution

To contribute to this project, send a pull request or find me on Twitter.

License

This project is licenced with the MIT license.

coderatio/simple-backup 适用场景与选型建议

coderatio/simple-backup 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.39k 次下载、GitHub Stars 达 56, 最近一次更新时间为 2019 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 coderatio/simple-backup 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 coderatio/simple-backup 我们能提供哪些服务?
定制开发 / 二次开发

基于 coderatio/simple-backup 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 57
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 56
  • Watchers: 0
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-30