phelium/mysql-backup
Composer 安装命令:
composer require phelium/mysql-backup
包简介
Backup easily your MySQL database !
README 文档
README
Introduction
This is a backup utility used to dump a database for backup. The backup file contains the queries to build the tables and insert the datas.
You can select some or all tables, compress the backup in ZIP or GZIP and start downloading automatically.
Installation
With Composer, add this line to your require section :
"phelium/mysql-backup": "dev-master"
Then run composer update.
Initialization
require 'vendor/autoload.php'; use Phelium\Component\MySQLBackup;
To initialize MySQLBackup, you must provide your database information :
$Dump = new MySQLBackup('server name', 'user name', 'password', 'db name', 'mysql port');
MySQL port default is 3306.
Usage
Add tables
By default, all tables are saved. If you want to save one or more tables, the functions addTable or addTables must be used:
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->addTable('posts'); // Add the posts table $Dump->addTables(array('users', 'comments')); // Add the users and comments tables
Exclude tables
You can exclude some tables of the backup. Use excludeTables function. The parameter must be an array containing tables name to exclude.
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->excludeTables(array(comments')); // Exclude comments table to the backup
Set the filename
By default, the name of the generated file is "dump_{database name}_{date}". With setFilename method, you can specify a different file name:
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->setFilename('bkp_'.time());
Do not dump the table schema or the datas
By default, the table schema (structure) and datas of each table are saved. However, it's possible not to save one or the other with setDumpStructure and setDumpDatas (default : true) :
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->setDumpStructure(false); // Not the structure $Dump->setDumpDatas(false); // Not the datas
Do not add CREATE DATABASE IF NOT EXISTS
By default, the CREATE DATABASE IF NOT EXISTS directive is added in top of the backup file. You can disable it with addCreateDatabaseIfNotExists (default : true) :
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->addCreateDatabaseIfNotExists(false); // Not add the CREATE DATABASE IF NOT EXISTS statment
Do not add DROP TABLE
By default, the DROP TABLE IF EXISTS directive is added before each CREATE TABLE. You can disable it with addDropTable (default : true) :
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->addDropTable(false); // Not add the DROP TABLE IF EXISTS statment
Do not add IF NOT EXISTS
By default, the IF NOT EXISTS directive is added during a CREATE TABLE. You can disable it with addIfNotExists (default : true) :
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->addIfNotExists(false); // Not add the IF NOT EXISTS statment
Compress file
To compress the output file, setCompress allows to use ZIP or GZIP (default : no compression) :
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->setCompress('zip'); // zip | gz | gzip
Delete file
The generated file can be deleted automatically with setDelete (default : false) :
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->setDelete(true);
Auto download
To download automatically the generated file, use setDownload (default : false) :
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->setDownload(true); // starts downloading
Execute the backup
To start backing up your database, use dump:
$Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->dump();
Full example
Here is an example to backup the blog database. Only the tables posts, comments and users are kept. Then compressed in ZIP format. The generated file is deleted from the server and the download starts automatically:
<?php require 'vendor/autoload.php'; use Phelium\Component\MySQLBackup; $Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump->addTables(array('posts', 'comments', 'users')); $Dump->setCompress('zip'); $Dump->setDelete(true); $Dump->setDownload(true); $Dump->dump(); // or $Dump = new MySQLBackup('localhost', 'root', '', 'blog'); $Dump ->addTables(array('posts', 'comment', 'users')); ->setCompress('zip'); ->setDelete(true); ->setDownload(true); ->dump();
phelium/mysql-backup 适用场景与选型建议
phelium/mysql-backup 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.35k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2015 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「dump」 「mysql」 「backup」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phelium/mysql-backup 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phelium/mysql-backup 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phelium/mysql-backup 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package will add the `dd` and `dump` helpers to your Phalcon application.
Dibi is Database Abstraction Library for PHP
Simple Twig extension improving templates debugging
nice output for debug functions for PHP 5.3
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.
统计信息
- 总下载量: 8.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 17
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-only
- 更新时间: 2015-02-20