diff --git a/api/app/lib/controllers/backups/index.js b/api/app/lib/controllers/backups/index.js index f8a4e6a..cb1bbfb 100644 --- a/api/app/lib/controllers/backups/index.js +++ b/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; diff --git a/web/client/src/sections/backups/actions/backups.js b/web/client/src/sections/backups/actions/backups.js index 5d9a594..6be208e 100644 --- a/web/client/src/sections/backups/actions/backups.js +++ b/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: '备份恢复下发', }, }); } \ No newline at end of file diff --git a/web/client/src/sections/backups/components/backupsModal.js b/web/client/src/sections/backups/components/backupsModal.js index b7fa5c5..ef89f85 100644 --- a/web/client/src/sections/backups/components/backupsModal.js +++ b/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 () => { diff --git a/web/client/src/sections/backups/containers/backupTask.js b/web/client/src/sections/backups/containers/backupTask.js index 73b4537..a5aaf3f 100644 --- a/web/client/src/sections/backups/containers/backupTask.js +++ b/web/client/src/sections/backups/containers/backupTask.js @@ -81,7 +81,8 @@ function Member(props) { render: (text, record) => { const options = []; options.push( - record?.source ? 恢复} title="恢复数据备份" @@ -93,18 +94,21 @@ function Member(props) { { window.open(record?.source) }}> 下载 : 下载 ) - options.push( -
是否确认删除该数据备份?
- } - onConfirm={() => handleDelete(record.id)} - okText="是" - cancelText="否" - > - 删除 -
) + if (record?.state != '备份中' && record?.state != '恢复中') { + options.push( +
是否确认删除该数据备份?
+ } + onConfirm={() => handleDelete(record.id)} + okText="是" + cancelText="否" + > + 删除 +
) + } + return options; }, diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index ab25d42..cfb0b9b 100644 --- a/web/client/src/utils/webapi.js +++ b/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 = {