haykabrahamyan / db-exporter
一个简单的包,通过shell将MySql数据库导出为.sql文件。
v1.0.4
2018-02-08 19:19 UTC
Requires
- php: >=5.3.0
- nao-pon/flysystem-google-drive: ~1.1
This package is auto-updated.
Last update: 2024-09-29 05:27:43 UTC
README
为什么需要搜索?你已经找到了,按照指南操作,让生活更美好:)
功能!
- 使用shell中的'mysqldump'命令将MySql数据库导出到SQL文件
- 自动将备份上传到Google Drive
- 支持Laravel Storage
在开始配置之前,请准备Google oAuth凭证
- GOOGLE_DRIVE_CLIENT_ID
- GOOGLE_DRIVE_CLIENT_SECRET
- GOOGLE_DRIVE_REFRESH_TOKEN
- GOOGLE_DRIVE_FOLDER_ID(可选)
安装
包需要php v5.3+版本才能运行。
安装依赖和devDependencies,并更新composer。
"require": { .... "haykabrahamyan/db-exporter": "^1.0.0", .... }
按照以下方式更新环境...
GOOGLE_DRIVE_CLIENT_ID=xxxx-yyyyyyyyy.apps.googleusercontent.com GOOGLE_DRIVE_CLIENT_SECRET=client_secret GOOGLE_DRIVE_REFRESH_TOKEN=1/xxxxxx GOOGLE_DRIVE_FOLDER_ID=null
如果你想将备份上传到您的drive根目录,请将drive文件夹设置为null
DbExporter_MYSQLDUMP=/usr/bin/mysqldump DbExporter_PATH=/var/www/html/public/
配置
将存储磁盘配置添加到config/filesystem.php
return [ // ... 'cloud' => 'google', // Optional: set Google Drive as default cloud storage 'disks' => [ // ... 'google' => [ 'driver' => 'google', 'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'), 'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'), 'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'), 'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'), ], // ... ], // ... ];
开发
将GoogleDriveServiceProvider.php保存到app/Providers,并将其添加到config/app.php中的providers数组中
App\Providers\GoogleDriveServiceProvider::class,
GoogleDriveServiceProvider.php
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class GoogleDriveServiceProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot() { \Storage::extend('google', function($app, $config) { $client = new \Google_Client(); $client->setClientId($config['clientId']); $client->setClientSecret($config['clientSecret']); $client->refreshToken($config['refreshToken']); $service = new \Google_Service_Drive($client); $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $config['folderId']); return new \League\Flysystem\Filesystem($adapter); }); } /** * Register the application services. * * @return void */ public function register() { // } }
如何使用
你已经完成,现在可以在代码的任何地方使用,包括通过简单调用安排文件
DbExporterController::doExport();
别忘了!将类放在文件顶部,该处应该调用Exporter
use Haykabrahamyan\DbExporter\DbExporterController;
许可证
MIT
自由软件,祝你好运! 你可以自由地通过以下BTC地址捐赠:132DKpgzGfYfFgqjR9EoG8EpYyAm84ksj2