feat(xo-server/metadata-backups): restore proxy backup (#5519)
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
- [Host/stats] Show interfaces' names in graph "Network throughput" instead of PIFs' indices (PR [#5483](https://github.com/vatesfr/xen-orchestra/pull/5483))
|
||||
- [Pool/advanced] Ability to define default migration network [#3788](https://github.com/vatesfr/xen-orchestra/issues/3788#issuecomment-743207834) (PR [#5465](https://github.com/vatesfr/xen-orchestra/pull/5465))
|
||||
- [Metadata backups] Ability to link a backup to a proxy (PR [#4206](https://github.com/vatesfr/xen-orchestra/pull/4206))
|
||||
- [Proxy] Support metadata backups (PRs [#5499](https://github.com/vatesfr/xen-orchestra/pull/5499) [#5517](https://github.com/vatesfr/xen-orchestra/pull/5517))
|
||||
- [Proxy] Support metadata backups (PRs [#5499](https://github.com/vatesfr/xen-orchestra/pull/5499) [#5517](https://github.com/vatesfr/xen-orchestra/pull/5517) [#5519](https://github.com/vatesfr/xen-orchestra/pull/5519))
|
||||
- [VM/console] Add button to connect to the VM via the local RDP client [#5495](https://github.com/vatesfr/xen-orchestra/issues/5495) (PR [#5523](https://github.com/vatesfr/xen-orchestra/pull/5523))
|
||||
- [VM] Ability to set guest secure boot (guest secure boot is available soon in XCP-ng) [#5502](https://github.com/vatesfr/xen-orchestra/issues/5502) (PR [#5527](https://github.com/vatesfr/xen-orchestra/pull/5527))
|
||||
|
||||
|
||||
@@ -809,11 +809,81 @@ export default class metadataBackup {
|
||||
async restoreMetadataBackup(id: string) {
|
||||
const app = this._app
|
||||
const logger = this._logger
|
||||
const message = 'metadataRestore'
|
||||
const [remoteId, dir, ...path] = id.split('/')
|
||||
const handler = await app.getRemoteHandler(remoteId)
|
||||
const metadataFolder = `${dir}/${path.join('/')}`
|
||||
|
||||
const { proxy, url, options } = await app.getRemoteWithCredentials(remoteId)
|
||||
if (proxy !== undefined) {
|
||||
let xapi
|
||||
if (dir === DIR_XO_POOL_METADATA_BACKUPS) {
|
||||
const poolUuid = path[1]
|
||||
const { allowUnauthorized, host, password, username } = await app.getXenServer(
|
||||
app.getXenServerIdByObject(poolUuid)
|
||||
)
|
||||
xapi = {
|
||||
allowUnauthorized,
|
||||
credentials: {
|
||||
username,
|
||||
password,
|
||||
},
|
||||
url: host,
|
||||
}
|
||||
}
|
||||
|
||||
const logsStream = await app.callProxyMethod(
|
||||
proxy,
|
||||
'backup.restoreMetadataBackup',
|
||||
{
|
||||
backupId: metadataFolder,
|
||||
remote: { url, options },
|
||||
xapi,
|
||||
},
|
||||
{
|
||||
assertType: 'iterator',
|
||||
}
|
||||
)
|
||||
|
||||
let rootTaskId
|
||||
const localTaskIds = { __proto__: null }
|
||||
for await (const log of logsStream) {
|
||||
const { event, message, taskId } = log
|
||||
|
||||
const common = {
|
||||
data: log.data,
|
||||
event: 'task.' + event,
|
||||
result: log.result,
|
||||
status: log.status,
|
||||
}
|
||||
|
||||
if (event === 'start') {
|
||||
const { parentId } = log
|
||||
if (parentId === undefined) {
|
||||
rootTaskId = localTaskIds[taskId] = logger.notice(message, common)
|
||||
} else {
|
||||
common.parentId = localTaskIds[parentId]
|
||||
localTaskIds[taskId] = logger.notice(message, common)
|
||||
}
|
||||
} else {
|
||||
const localTaskId = localTaskIds[taskId]
|
||||
if (localTaskId === rootTaskId && dir === DIR_XO_CONFIG_BACKUPS && log.status === 'success') {
|
||||
try {
|
||||
await app.importConfig(log.result)
|
||||
} catch (error) {
|
||||
common.result = serializeError(error)
|
||||
common.status = 'failure'
|
||||
}
|
||||
}
|
||||
|
||||
common.taskId = localTaskId
|
||||
logger.notice(message, common)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const message = 'metadataRestore'
|
||||
const handler = await app.getRemoteHandler(remoteId)
|
||||
|
||||
const taskId = logger.notice(message, {
|
||||
event: 'task.start',
|
||||
data: JSON.parse(String(await handler.readFile(`${metadataFolder}/metadata.json`))),
|
||||
|
||||
Reference in New Issue
Block a user