mysql到s3_Laravel 5.6-将MySQL数据库备份到S3?

我尝试将整个MySQL数据库备份到S3,如下所示:

namespace App\Console\Commands;

use Carbon\Carbon;

use Illuminate\Console\Command;

use Illuminate\Support\Facades\Storage;

use Symfony\Component\Process\Process;

class DatabaseBackup extends Command {

/**

* The name and signature of the console command.

*

* @var string

*/

protected $signature = 'backup:database';

/**

* The console command description.

*

* @var string

*/

protected $description = 'Take a backup of the entire DB and upload to S3.';

/**

* Create a new command instance.

*

* @return void

*/

public function __construct()

{

parent::__construct();

}

/**

* Execute the console command.

*

* @return mixed

*/

public function handle()

{

$date = Carbon::now()->format('Y-m-d_h-i');

$user = env('DB_USERNAME');

$password = env('DB_PASSWORD');

$database = env('DB_DATABASE');

$command = "mysqldump --user={$user} -p{$password} {$database} > {$date}.sql";

$process = new Process($command);

$process->start();

while ($process->isRunning()) {

$s3 = Storage::disk('s3');

$s3->put('gallery-app-db/' . $date . ".sql", file_get_contents("{$date}.sql"));

unlink("{$date}.sql");

}

}

}

但跑步时

php artisan backup:database

然后查看bucket.sql文件,并在本地下载.sql文件,它显示如下,而不是文件中的实际数据库/表:

B9R2W.png

知道如何让.sql dump实际工作并备份真正的数据库及其所有表,而不是使用文件吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值