TP---数据库的备份、下载、还原、删除
1、首先需要下载相应的类库,并把类库方法.\extends\org\下。点击下载
2、控制器内容:
<?php
namespace app\index\controller;
use think\Controller;
class Backup extends Controller
{
//数据库备份
public function index()
{
//获取操作内容:(备份/下载/还原/删除)数据库
$type = input("type");
//获取需要操作的数据库名字
$name = input("name");
$backup = new \org\Baksql(\think\Config::get("database"));
switch ($type) {
//备份
case "backup":
$info = $backup->backup();
$this->success("$info", 'index/backup/bak');
break;
//下载
case "dowonload":
$info = $backup->downloadFile($name);
$this->success("$info", 'index/backup/bak');
break;
//还原
case "restore":
$info = $backup->restore($name);
$this->success("$info", 'index/backup/bak');
break;
//删除
case "del":
$info = $backup->delfilename($name);
$this->success("$info", 'index/backup/bak');
break;
//如果没有操作,则查询已备份的所有数据库信息
default:
return $this->fetch("index", ["list" => array_reverse($sql->get_filelist())]);//将信息由新到老排序
}
}
}
3、视图中:
<div class="ibox-content">
<div class="">
<a class="btn btn-primary " href="{:url('index',['type'=>'backup'])}"onclick="return confirm('备份数据的时间较长,确定要备份所有数据吗?')"><i class="glyphicon glyphicon-plus"></i> <span class="bold">添加备份</span></a>
</div>
<table class="table table-striped table-bordered table-hover dataTables-example" style="text-align: center">
<thead>
<tr>
<td>序号</td>
<td>备份名称</td>
<td>备份时间</td>
<td>备份大小</td>
<td>操作</td>
</tr>
</thead>
<tbody>
{volist name="list" id="vo"}
<tr class="gradeX" >
<td>{$key+1}</td>
<td>{$vo.name}</td>
<td>{$vo.time}</td>
<td>{$vo.size}</td>
<td width="25%">
<a href="{:url('bak',['type'=>'dowonload','name'=>$vo.name])}" class="btn btn-success "><i class="glyphicon glyphicon-download-alt"></i> <span class="bold">下载</span></a>
<a href="{:url('bak',['type'=>'restore','name'=>$vo.name])}" class="btn btn-info " onclick="return confirm('备份还原后仅会显示当前备份的数据库的信息,您确定还原备份吗 ?')"><i class="glyphicon glyphicon-repeat"></i> <span class="bold">还原</span></a>
<a href="{:url('bak',['type'=>'del','name'=>$vo.name])}" class="btn btn-warning" onclick="return confirm('数据库备份一旦删除不可找回,您确定操作吗?')"><i class="fa fa-warning"></i> <span class="bold">删除</span></a>
</td>
</tr>
{/volist}
</tbody>
</table>
</div>
效果图:
博客园:https://www.cnblogs.com/huixincode
如果此文章对您有所帮助记得打赏哦,一分也是对我的支持和鼓励,谢谢!
转载文章请务必保留出处和署名,谢谢!
如果此文章对您有所帮助记得打赏哦,一分也是对我的支持和鼓励,谢谢!
转载文章请务必保留出处和署名,谢谢!