Browse Source

(*)数据恢复功能完善

master
peng.peng 2 years ago
parent
commit
e9ac05b446
  1. 18
      api/app/lib/controllers/backups/index.js
  2. 4
      web/client/src/sections/backups/actions/backups.js
  3. 1
      web/client/src/sections/backups/components/backupsModal.js
  4. 30
      web/client/src/sections/backups/containers/backupTask.js
  5. 1
      web/client/src/utils/webapi.js

18
api/app/lib/controllers/backups/index.js

@ -58,10 +58,11 @@ function addBackups(opts) {
// const url = '10.8.30.160:8085/dumpDB?dbHost=10.8.30.75&dbPort=5432&user=postgres&password=1234&dbName=Anxinyun0916'//测试使用
const url = backupsUrl + `/dumpDB?dbHost=${host}&dbPort=${port}&user=${user}&password=${password}&dbName=${database}`;
request.post(url).then(res => {
const { fileInfo: { name, size }, message } = res.body
const { fileInfo: { name, size }, code } = res.body
models.Backups.update({
size, source: name, state: message, completeTime: moment()
size, source: name, state: code == 200 ? '备份成功' : '备份失败', completeTime: moment()
}, { where: { id: backup.id } })
if (code != 200) ctx.fs.logger.error(`path: ${ctx.path}, error: ${message}`);
})
ctx.status = 204;
@ -122,7 +123,7 @@ function deleteBackups(opts) {
}
}
// 新增数据备份
//备份恢复
function restore(opts) {
return async function (ctx, next) {
const { backupsUrl } = opts;
@ -130,18 +131,21 @@ function restore(opts) {
try {
let rslt = ctx.request.body;
const { id, source, databases: { database, host, password, port, user } } = ctx.request.body
await models.Backups.update({
state: '恢复中',
}, { where: { id: id } })
//调用后端备份接口
const url = backupsUrl + `/restoreDB?dbHost=${host}&dbPort=${port}&user=${user}&password=${password}&dbName=${database}&backFileName=${source}`;
request.post(url).then(res => {
const { fileInfo: { name, size }, message } = res.body
const { code, message } = res.body
models.Backups.update({
size, source: name, state: message, completeTime: moment()
state: code == 200 ? '恢复成功' : '恢复失败',
}, { where: { id: id } })
if (code != 200) ctx.fs.logger.error(`path: ${ctx.path}, error: ${message}`);
})
ctx.status = 204;
ctx.body = { message: '备份还原成功' }
ctx.body = { message: '备份恢复成功' }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;

4
web/client/src/sections/backups/actions/backups.js

@ -24,7 +24,7 @@ export function addBackups(params) {
actionType: 'ADD_BACKUPS_REPORT',
url: ApiTable.addBackups,
msg: {
option: '数据备份新增',
option: '数据备份新增下发',
},
});
}
@ -62,7 +62,7 @@ export function restoreBackups(params) {
actionType: 'RESTORE_BACKUPS_REPORT',
url: ApiTable.restoreBackups,
msg: {
option: '备份恢复',
option: '备份恢复下发',
},
});
}

1
web/client/src/sections/backups/components/backupsModal.js

@ -54,6 +54,7 @@ export default (props) => {
name="databases"
label='数据源'
placeholder="请选择数据源"
tooltip={title == '恢复数据备份' ? '恢复前请确保恢复数据源数据库为空数据库,且恢复地址存在与备份地址相同数据库用户' : ''}
allowClear
secondary
request={async () => {

30
web/client/src/sections/backups/containers/backupTask.js

@ -81,7 +81,8 @@ function Member(props) {
render: (text, record) => {
const options = [];
options.push(
record?.source ? <BackupsModal
(record?.state != '恢复中' && record?.source) ? <BackupsModal
editData={record}
dataSources={dataSources}
triggerRender={<a type='primary'>恢复</a>}
title="恢复数据备份"
@ -93,18 +94,21 @@ function Member(props) {
<a a onClick={() => { window.open(record?.source) }}> 下载</a> : <a style={{ color: 'gray' }}></a>
)
options.push(
<Popconfirm
key="del"
placement="top"
title={<><div>是否确认删除该数据备份</div>
</>}
onConfirm={() => handleDelete(record.id)}
okText="是"
cancelText="否"
>
<a>删除</a>
</Popconfirm>)
if (record?.state != '备份中' && record?.state != '恢复中') {
options.push(
<Popconfirm
key="del"
placement="top"
title={<><div>是否确认删除该数据备份</div>
</>}
onConfirm={() => handleDelete(record.id)}
okText="是"
cancelText="否"
>
<a>删除</a>
</Popconfirm>)
}
return options;
},

1
web/client/src/utils/webapi.js

@ -89,6 +89,7 @@ export const ApiTable = {
getBackupsList: 'meta/backups',
addBackups: 'meta/backups',
modifyBackups: 'meta/backups/{id}',
restoreBackups:'backups/restore'
};
export const RouteTable = {

Loading…
Cancel
Save