我将这个安装到我的laravel项目中:
backup-manager/laravel
league/flysystem-dropbox因为我可以备份我的数据库到dropbox,但它可以用php artisan终端来完成,如何在我的设置页面上做一个按钮,当我点击时,它可以调用这个备份功能?
有没有可以调用的函数来触发这个备份函数?或者它只是可以由php artisan来完成?
我试着奔跑
Artisan::call('db:backup');并显示错误
Maximum execution time of 60 seconds exceeded当我从终端运行时,它工作正常
如何从我的控制器运行它?
php artisan db:backup --database=pgsql --destination=dropbox --destinationPath=`date +\%d-%m-%Y %H:%i:%s`-digitization.sql --compression=null请谁来帮帮我..
这是我使用ajax编写的脚本
<script type="text/javascript">
$("#backup").click(function(){
var url = $(this).data("url");
$.ajax({
url: url
}).done(function() {
alert("asdsad");
});
});
</script>发布于 2015-11-19 14:34:03
试试这个,
您可以从code itself调用artisan命令。
像这样,
Route::get('/backupdatabase', function () {
$exitCode = Artisan::call('db:backup');
}如果你的数据库太大,在浏览器上可能无法工作,所以最好与cron作业一起使用。您可以找到cron作业设置文档here。还有一些packages。
希望能有所帮助..。
发布于 2015-11-19 14:36:06
您可以通过代码调用artisan命令。http://laravel.com/docs/5.1/artisan#calling-commands-via-code
所以如果你需要运行这个
压缩php artisan数据库:backup --database=pgsql --destination=dropbox --destinationPath=date +\%d-%m-%Y %H:%i:%s-digitization.sql --
=空
然后你可以这样做:
Route::get('/db_backup', function () {
var $now = Carbon\Carbon::now();
$exitCode = Artisan::call('db:backup',
[
'--database' => 'pgsql',
'--destination' => 'dropbox',
'--destinationPath' => $now->toDateTimeString().'-digitization.sql',
'--compression' => null
]
);
});发布于 2016-06-19 00:44:05
1)在刀片式服务器中创建按钮:
<button onclick="backup()"></button>2)在javascript部分:
var token = $('input[name = _token]').val();
function backup() {
$.ajax({
type: "POST",
url: '/admin/system/db-backup',
data: {
_token: token,
},
success: function (result) {
alert("ok")
},
error: function (errors) {
alert("error");
}
});
}3)在routes.php中:
Route::post('/admin/system/db-backup', [
'as' => 'system.dbBackup',
'uses' => 'Website\SystemController@postDbBackUp'
]);4)在控制器(SystemController.php)中:
public function postDbBackUp () {
$now = Carbon::now()->format("Y-m-d-H-m-i").'-backup.sql';
try {
Artisan::call('db:backup',
[
'--database' => 'mysql',
'--destination' => 'local',
'--destinationPath' =>$now,
'--compression' => 'gzip'
]
);
}
catch(\Exception $e) {
return Response::json([
'success' => false,
'errors' => ""
], 400);
}
return Response::json([
'success' => true,
'message' => 'success'
]);
}https://stackoverflow.com/questions/33796696
复制相似问题