Laravel备份管理器

时间:2018-11-25 11:14:55

标签: php database laravel backup artisan

我安装了Laravel备份管理器(用于数据库备份管理器1.3.1的Laravel驱动程序),当前,我能够使用命令行来备份数据库。它正在工作。

php artisan db:backup --database=mysql --destination=local --destinationPath=project --timestamp="h-d-m-Y" --compression=null

但是我要为此设置一个视图,所以这是我的视图,

@extends('main')
@section('title',' New Item Category')
@section('ribbon','Item Management')
@section('content')
<div class="card">
        <button class="btn btn-success" id="backup">Backup</button>
</div>
<script>
        $( document ).ready(function() {
        $('#backup').click(function(){

            $.ajax({
                url: BASE + '/backup_post',
                type: 'POST',
                dataType: 'JSON',
                //data: $.param(params),
                success: function (response) {
                    alert(response);
                }
            });
        });
        });
</script>
@endsection('content')

这是我的控制器

<?php
namespace App\Http\Controllers;
// ini_set('max_execution_time', 180);
// ini_set('memory_limit', '-1');
use Illuminate\Http\Request;
use Carbon\Carbon;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Response;

class BackupController extends Controller
{
    public function index(){
        return view('system_mgmt.backup');
    }

    public function backup_post () {
        $now =  Carbon::now()->format("Y-m-d-H-m-i").'-backup.sql';
        //return response()->json(['status' => 'success']);
         try {
             Artisan::call('db:backup',
                 [

                    '--database' => 'mysql',
                    '--destination' => 'local',
                    '--destinationPath' => $now,
                    '--compression' => null,
                 ]
             );
         }
         catch(\Exception $e) {
             return Response::json([
                 'success' => false,
                 'errors' => ""
             ], 400);
         }
         return Response::json([
             'success' => true,
             'message' => 'success'
         ]);

     }
}

但是我正在关注FatalErrorException

enter image description here

告诉我该怎么做。谢谢

0 个答案:

没有答案