|
|
@ -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; |
|
|
|