first commit
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
{extend name="../../base/view/common/base" /}
|
||||
<!-- 主体 -->
|
||||
{block name="body"}
|
||||
<div class="p-page">
|
||||
<div class="gg-form-bar border-t border-x">
|
||||
<h3 class="pb-3">数据还原</h3>
|
||||
</div>
|
||||
<table cellspacing="0" cellpadding="0" border="0" class="layui-table layui-table-form">
|
||||
<tr style="background-color:#FAFAFA">
|
||||
<th style=" text-align: center; font-weight: 800;"><span>文件名称</span></th>
|
||||
<th style=" text-align: center; font-weight: 800;"><span>文件格式</span></th>
|
||||
<th style=" text-align: center; font-weight: 800;"><span>分隔符</span></th>
|
||||
<th style=" text-align: center; font-weight: 800;"><span>文件总大小</span></th>
|
||||
<th style=" text-align: center; font-weight: 800;"><span>分卷总数</span></th>
|
||||
<th style=" text-align: center; font-weight: 800; width:222px"><span>操作</span></th>
|
||||
</tr>
|
||||
{empty name="list"}
|
||||
<tr>
|
||||
<td colspan="6" align="center" style="padding:20px 0; color:#999">暂无备份数据</td>
|
||||
</tr>
|
||||
{/empty}
|
||||
{volist name="list" id="vo" key="k"}
|
||||
<tr style="background-color: #fafafa;">
|
||||
<td><strong>备份时间:{$vo.time}</strong>{if $vo.timespan == $lock_time}<span style="color:red; margin-left:20px;">该备份不是完整备份,请删除重新备份</span>{/if}</td>
|
||||
<td align="center"><span>.sql</span></td>
|
||||
<td align="center"><span>{$vo.data.compress}</span></td>
|
||||
<td align="center"><span>{:format_bytes($vo.data.size)}</span></td>
|
||||
<td align="center"><span>{$vo.data.part}</span></td>
|
||||
<td align="center">
|
||||
<div class="layui-btn-group" data-time='{$vo.timespan}'>
|
||||
{if $vo.timespan == $lock_time}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="reset">清除不完整的备份</a>
|
||||
{else/}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="import">数据还原</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除备份</a>
|
||||
{/if}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{for start="0" end="$vo.data.part" step="1"}
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
{:date("Ymd",$vo.timespan)}{$vo.data.compress}{:date("His",$vo.timespan)}{$vo.data.compress}{$i+1}.sql
|
||||
</td>
|
||||
<td align="center">
|
||||
<a class="layui-btn layui-btn-xs" href='/home/database/downfile?time={$vo.data.time}&part={$i+1}'>下载备份(分卷{$i+1})</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/for}
|
||||
{/volist}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/block}
|
||||
<!-- /主体 -->
|
||||
|
||||
<!-- 脚本 -->
|
||||
{block name="script"}
|
||||
<script>
|
||||
function gouguInit() {
|
||||
function importData(data) {
|
||||
if (data.code == 0) {
|
||||
console.log(data.msg);
|
||||
layer.closeAll();
|
||||
layer.msg(data.msg, { time: 200000 });
|
||||
if ($.isPlainObject(data.data)) {
|
||||
$.ajax({
|
||||
url: "/home/database/import",
|
||||
type: 'get',
|
||||
data: { "part": data.data.part, "start": data.data.start, time: data.data.time },
|
||||
success: function (res) {
|
||||
importData(res);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
layer.msg(data.msg);
|
||||
window.onbeforeunload = function () { return null; }
|
||||
}
|
||||
} else {
|
||||
layer.msg(data.msg);
|
||||
}
|
||||
}
|
||||
//监听行工具事件
|
||||
$('[lay-event="import"]').on('click', function () {
|
||||
var time = $(this).parent().data('time');
|
||||
layer.confirm('确认要还原该备份吗?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
layer.msg("数据还原中...", { time: 200000 });
|
||||
$.ajax({
|
||||
url: "/home/database/import?time=" + time,
|
||||
type: 'post',
|
||||
success: function (res) {
|
||||
importData(res);
|
||||
}
|
||||
})
|
||||
window.onbeforeunload = function () { return "正在还原数据库,请不要关闭!" }
|
||||
layer.close(index);
|
||||
});
|
||||
return false;
|
||||
})
|
||||
|
||||
$('[lay-event="del"]').on('click', function () {
|
||||
var time = $(this).parent().data('time');
|
||||
layer.confirm('确认要删除该备份吗?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
$.ajax({
|
||||
url: "/home/database/del",
|
||||
data: { 'time': time },
|
||||
success: function (res) {
|
||||
layer.msg(res.msg);
|
||||
if (res.code == 0) {
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
})
|
||||
layer.close(index);
|
||||
});
|
||||
return false;
|
||||
})
|
||||
|
||||
$('[lay-event="reset"]').on('click', function () {
|
||||
var time = $(this).parent().data('time');
|
||||
layer.confirm('确认要清除该备份吗?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
$.ajax({
|
||||
url: "/home/database/del",
|
||||
data: { 'time': time, 'lock': 1 },
|
||||
success: function (res) {
|
||||
layer.msg(res.msg);
|
||||
if (res.code == 0) {
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
})
|
||||
layer.close(index);
|
||||
});
|
||||
return false;
|
||||
})
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
<!-- /脚本 -->
|
||||
@@ -0,0 +1,201 @@
|
||||
{extend name="../../base/view/common/base" /}
|
||||
<!-- 主体 -->
|
||||
{block name="body"}
|
||||
<div class="p-page">
|
||||
<table class="layui-hide" id="backup" lay-filter="backup"></table>
|
||||
</div>
|
||||
<script type="text/html" id="toolbarDemo">
|
||||
<div class="layui-btn-group">
|
||||
<span class="layui-btn layui-btn-sm layui-btn-normal" lay-event="backup">数据备份</span>
|
||||
</div>
|
||||
<span id="dataTips" style="font-size:12px; margin-left:10px"></span>
|
||||
</script>
|
||||
{/block}
|
||||
<!-- /主体 -->
|
||||
<!-- 脚本 -->
|
||||
{block name="script"}
|
||||
<script>
|
||||
function gouguInit() {
|
||||
var table = layui.table, form = layui.form;
|
||||
var tableIns = table.render({
|
||||
elem: '#backup',
|
||||
title: '数据备份',
|
||||
toolbar: '#toolbarDemo',
|
||||
defaultToolbar: false,
|
||||
url: "/home/database/database", //数据接口
|
||||
page: false,
|
||||
cols: [
|
||||
[ //表头
|
||||
{ type: 'checkbox' },
|
||||
{
|
||||
field: 'name',
|
||||
title: '数据表',
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 100,
|
||||
templet: function (d) {
|
||||
return '<span id="table_' + d.name + '">-</span>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'engine',
|
||||
title: '存储引擎',
|
||||
align: 'center',
|
||||
width: 80
|
||||
}, {
|
||||
field: 'row_format',
|
||||
title: '行格式',
|
||||
align: 'center',
|
||||
width: 80
|
||||
}, {
|
||||
field: 'rows',
|
||||
title: '行数',
|
||||
align: 'center',
|
||||
width: 60,
|
||||
}, {
|
||||
field: 'data_size',
|
||||
title: '字节数',
|
||||
align: 'center',
|
||||
width: 80
|
||||
}, {
|
||||
field: 'data_length',
|
||||
title: '数据大小',
|
||||
align: 'center',
|
||||
width: 80
|
||||
}, {
|
||||
field: 'comment',
|
||||
title: '数据表注释'
|
||||
}, {
|
||||
field: 'create_time',
|
||||
title: '创建时间',
|
||||
width: 160,
|
||||
align: 'center'
|
||||
}
|
||||
]
|
||||
],
|
||||
done: function (res, curr, count) {
|
||||
$('#dataTips').html(res.msg);
|
||||
}
|
||||
});
|
||||
|
||||
//递归备份表
|
||||
function backup(tab, status, table) {
|
||||
layer.closeAll();
|
||||
layer.msg("备份中...,请勿关闭本页面", { time: 200000 });
|
||||
$.get("/home/database/backup", tab, function (data) {
|
||||
if (data.code == 0) {
|
||||
showmsg(data.data.tab.table, data.msg);
|
||||
if (data.data.tab.start == 'ok') {
|
||||
layer.msg('备份完成');
|
||||
window.onbeforeunload = function () { return null }
|
||||
return;
|
||||
}
|
||||
backup(data.data.tab, tab.id != data.data.tab.id);
|
||||
} else {
|
||||
layer.msg('立即备份');
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
|
||||
//修改备份状态
|
||||
function showmsg(table, msg) {
|
||||
console.log(table);
|
||||
$("#table_" + table).addClass('span-color-2').html(msg);
|
||||
}
|
||||
//监听行工具事件
|
||||
table.on('toolbar(backup)', function (obj) {
|
||||
var checkData = table.checkStatus(obj.config.id).data;
|
||||
var len = checkData.length;
|
||||
var tables = [];
|
||||
if (len == 0) {
|
||||
layer.msg('请先选择表');
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < len; i++) {
|
||||
tables.push(checkData[i].name);
|
||||
}
|
||||
if (obj.event === 'backup') {
|
||||
layer.confirm('系统自带的备份功能仅是辅助工具,建议使用第三方专业的工具备份更安全!<br>确认要备份选中的' + len + '个数据表吗?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
$.ajax({
|
||||
url: "/home/database/backup",
|
||||
type: 'post',
|
||||
data: { 'tables': tables },
|
||||
success: function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg("开始备份,请不要关闭本页面!");
|
||||
window.onbeforeunload = function () { return "正在备份数据库,请不要关闭!" }
|
||||
backup(res.data.tab);
|
||||
}
|
||||
if (res.code == 2) {
|
||||
layer.confirm('检测到有一个备份任务未完成,请先清除未完成的备份', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
$.ajax({
|
||||
url: "/home/database/del",
|
||||
data: { 'lock': 1 },
|
||||
success: function (res) {
|
||||
layer.msg(res.msg);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
else {
|
||||
layer.msg(res.msg);
|
||||
}
|
||||
}
|
||||
})
|
||||
layer.close(index);
|
||||
});
|
||||
} else if (obj.event === 'optimize') {
|
||||
layer.confirm('确认要优化选中的' + len + '个数据表吗?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
$.ajax({
|
||||
url: "/home/database/optimize",
|
||||
type: 'post',
|
||||
data: { 'tables': tables },
|
||||
success: function (res) {
|
||||
layer.msg(res.msg);
|
||||
if (res.code == 0) {
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
})
|
||||
layer.close(index);
|
||||
});
|
||||
} else if (obj.event === 'repair') {
|
||||
layer.confirm('确认要修复选中的' + len + '个数据表吗?', {
|
||||
icon: 3,
|
||||
title: '提示'
|
||||
}, function (index) {
|
||||
$.ajax({
|
||||
url: "/home/database/repair",
|
||||
type: 'post',
|
||||
data: { 'tables': tables },
|
||||
success: function (res) {
|
||||
layer.msg(res.msg);
|
||||
if (res.code == 0) {
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
})
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
<!-- /脚本 -->
|
||||
Reference in New Issue
Block a user