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. 6
      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 = '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}`; const url = backupsUrl + `/dumpDB?dbHost=${host}&dbPort=${port}&user=${user}&password=${password}&dbName=${database}`;
request.post(url).then(res => { request.post(url).then(res => {
const { fileInfo: { name, size }, message } = res.body const { fileInfo: { name, size }, code } = res.body
models.Backups.update({ models.Backups.update({
size, source: name, state: message, completeTime: moment() size, source: name, state: code == 200 ? '备份成功' : '备份失败', completeTime: moment()
}, { where: { id: backup.id } }) }, { where: { id: backup.id } })
if (code != 200) ctx.fs.logger.error(`path: ${ctx.path}, error: ${message}`);
}) })
ctx.status = 204; ctx.status = 204;
@ -122,7 +123,7 @@ function deleteBackups(opts) {
} }
} }
// 新增数据备份 //备份恢复
function restore(opts) { function restore(opts) {
return async function (ctx, next) { return async function (ctx, next) {
const { backupsUrl } = opts; const { backupsUrl } = opts;
@ -130,18 +131,21 @@ function restore(opts) {
try { try {
let rslt = ctx.request.body; let rslt = ctx.request.body;
const { id, source, databases: { database, host, password, port, user } } = 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}`; const url = backupsUrl + `/restoreDB?dbHost=${host}&dbPort=${port}&user=${user}&password=${password}&dbName=${database}&backFileName=${source}`;
request.post(url).then(res => { request.post(url).then(res => {
const { fileInfo: { name, size }, message } = res.body const { code, message } = res.body
models.Backups.update({ models.Backups.update({
size, source: name, state: message, completeTime: moment() state: code == 200 ? '恢复成功' : '恢复失败',
}, { where: { id: id } }) }, { where: { id: id } })
if (code != 200) ctx.fs.logger.error(`path: ${ctx.path}, error: ${message}`);
}) })
ctx.status = 204; ctx.status = 204;
ctx.body = { message: '备份还原成功' } ctx.body = { message: '备份恢复成功' }
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;

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

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

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

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

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

@ -81,7 +81,8 @@ function Member(props) {
render: (text, record) => { render: (text, record) => {
const options = []; const options = [];
options.push( options.push(
record?.source ? <BackupsModal (record?.state != '恢复中' && record?.source) ? <BackupsModal
editData={record}
dataSources={dataSources} dataSources={dataSources}
triggerRender={<a type='primary'>恢复</a>} triggerRender={<a type='primary'>恢复</a>}
title="恢复数据备份" title="恢复数据备份"
@ -93,6 +94,7 @@ function Member(props) {
<a a onClick={() => { window.open(record?.source) }}> 下载</a> : <a style={{ color: 'gray' }}></a> <a a onClick={() => { window.open(record?.source) }}> 下载</a> : <a style={{ color: 'gray' }}></a>
) )
if (record?.state != '备份中' && record?.state != '恢复中') {
options.push( options.push(
<Popconfirm <Popconfirm
key="del" key="del"
@ -105,6 +107,8 @@ function Member(props) {
> >
<a>删除</a> <a>删除</a>
</Popconfirm>) </Popconfirm>)
}
return options; return options;
}, },

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

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

Loading…
Cancel
Save