备份工具 / 备份
FDevs 备份组件
0.4.0
2019-01-09 09:22 UTC
Requires
- php: ^5.6 || ^7.0
- symfony/filesystem: ~2.8|~3.0|~4.0
- symfony/options-resolver: ~2.8|~3.0|~4.0
- symfony/process: >2.0,<4.2
Requires (Dev)
- knplabs/gaufrette: ^0.2.1
Suggests
- knplabs/gaufrette: use with different filesystem
README
安装
备份使用Composer,请访问Composer官网获取更多信息。
以下简单的命令将安装 fdevs/backup
到您的项目中。它还会在您的 composer.json
中添加一个新条目并更新 composer.lock
。
composer require fdevs/backup
使用示例
带有压缩的dump/restore文件夹
<?php use FDevs\Backup\Manager; use FDevs\Backup\Source\Folder; use FDevs\Backup\Filesystem\LocalFile; use FDevs\Backup\Compress\TarGzip; $sourceFolder = '';//your source folder. for example with images $tmpFolder = ''; //tmp folder MST be writable $dumpFolder = '';//dump folder if ypu use local dump $source = new Folder($sourceFolder,$tmpFolder); $filesystem = new LocalFile($dumpFolder); $compress = new TarGzip(); $manager = new Manager($source,$filesystem,$compress); $key = $manager->dump(); echo $key;//show key dumped folder $manager->restore($key);//restore data $manager->keyList();//show all keys in uses filesystem
带有压缩的dump/restore mongodb
<?php use FDevs\Backup\Manager; use FDevs\Backup\Source\MongoDB; use FDevs\Backup\Filesystem\LocalFile; use FDevs\Backup\Compress\TarGzip; $dumpFolder = '';//dump folder if ypu use local dump $tmpFolder = ''; //tmp folder MUST be writable $options = [ //'host' => 'localhost' Specifies a resolvable hostname for the mongod to which to connect. default localhost //'port' => 27017 Specifies the TCP port on which the MongoDB instance listens for client connections. Delault 27017 //'db'=>'dbname' Specifies a database to backup. If you do not specify a database, copies all databases in this instance into the dump files. //'collection'=>'collection' Specifies a collection to backup. If you do not specify a collection, this option copies all collections in the specified database or instance to the dump files. //'username'=>'username' Specifies a username with which to authenticate to a MongoDB database that uses authentication. //'password'=>'password' Specifies a password with which to authenticate to a MongoDB database that uses authentication. //'override' => false Before restoring the collections from the dumped backup, drops the collections from the target database. ]; $source = new MongoDB($tmpFolder); $filesystem = new LocalFile($dumpFolder); $compress = new TarGzip(); $manager = new Manager($source,$filesystem,$compress); $key = $manager->dump($options); echo $key;//show key dumped folder $manager->restore($key,$options);//restore data $manager->keyList();//show all keys in uses filesystem
带有压缩的dump/restore mysql
<?php use FDevs\Backup\Manager; use FDevs\Backup\Source\Mysql; use FDevs\Backup\Filesystem\LocalFile; use FDevs\Backup\Compress\TarGzip; $dumpFolder = __DIR__.'/dump/';//dump folder if ypu use local dump $tmpFolder = __DIR__.'/tmp/'; //tmp folder MUST be writable $options = [ 'host' => 'localhost',// Specifies a resolvable hostname for the mysqldump to which to connect. default localhost 'port' => 3306, //Specifies the TCP port on which the Mysql server instance listens for client connections. Delault 3306 'databases'=>['dbname'],// Specifies a database to backup. If you do not specify a database, copies all databases in this instance into the dump files. 'user'=>'symfony', //Specifies a username with which to authenticate to a Mysql database that uses authentication. 'password'=>'symfony', //Specifies a password with which to authenticate to a Mysql database that uses authentication. 'override' => false,//Before restoring the collections from the dumped backup, drops the tables from the target database. ]; $source = new Mysql($tmpFolder); $filesystem = new LocalFile($dumpFolder); $compress = new TarGzip(); $manager = new Manager($source,$filesystem,$compress); $key = $manager->dump($options); echo $key;//show key dumped folder $manager->restore($key,$options);//restore data $manager->keyList();//show all keys in uses filesystem
许可协议
此库采用MIT许可协议。请参阅库中的完整许可协议
LICENSE