fix(backups,xo-server): don't backup VMs created by Health Check

This commit is contained in:
Florent Beauchamp 2023-11-29 13:15:31 +00:00 committed by Julien Fontanet
parent 87a9fbe237
commit a5acc7d267
5 changed files with 22 additions and 5 deletions

View File

@ -16,20 +16,29 @@ async function resolveUuid(xapi, cache, uuid, type) {
return cache.get(uuid)
}
export class ImportVmBackup {
constructor({ adapter, metadata, srUuid, xapi, settings: { newMacAddresses, mapVdisSrs = {} } = {} }) {
constructor({
adapter,
metadata,
srUuid,
xapi,
settings: { additionnalVmTag, newMacAddresses, mapVdisSrs = {} } = {},
}) {
this._adapter = adapter
this._importIncrementalVmSettings = { newMacAddresses, mapVdisSrs }
this._importIncrementalVmSettings = { additionnalVmTag, newMacAddresses, mapVdisSrs }
this._metadata = metadata
this._srUuid = srUuid
this._xapi = xapi
}
async #decorateIncrementalVmMetadata(backup) {
const { mapVdisSrs } = this._importIncrementalVmSettings
const { additionnalVmTag, mapVdisSrs } = this._importIncrementalVmSettings
const xapi = this._xapi
const cache = new Map()
const mapVdisSrRefs = {}
if (additionnalVmTag !== undefined) {
backup.vm.tags.push(additionnalVmTag)
}
for (const [vdiUuid, srUuid] of Object.entries(mapVdisSrs)) {
mapVdisSrRefs[vdiUuid] = await resolveUuid(xapi, cache, srUuid, 'SR')
}

View File

@ -96,6 +96,9 @@ export const MixinRemoteWriter = (BaseClass = Object) =>
metadata,
srUuid,
xapi,
settings: {
additionnalVmTag: 'xo:no-bak=Health Check',
},
}).run()
const restoredVm = xapi.getObject(restoredId)
try {

View File

@ -58,7 +58,7 @@ export const MixinXapiWriter = (BaseClass = Object) =>
)
}
const healthCheckVm = xapi.getObject(healthCheckVmRef) ?? (await xapi.waitObject(healthCheckVmRef))
await healthCheckVm.add_tag('xo:no-bak=Health Check')
await new HealthCheckVmBackup({
restoredVm: healthCheckVm,
xapi,

View File

@ -16,6 +16,8 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Backup/HealthCheck] Don't backup VM created by health check when using smart mode (PR [#7173](https://github.com/vatesfr/xen-orchestra/pull/7173))
### Packages to release
> When modifying a package, add it here with its release type.

View File

@ -626,7 +626,10 @@ export default class BackupNg {
.run(async () => {
const app = this._app
const xapi = app.getXapi(srId)
const restoredId = await this.importVmBackupNg(backupId, srId, settings)
const restoredId = await this.importVmBackupNg(backupId, srId, {
...settings,
additionnalVmTag: 'xo:no-bak=Health Check',
})
const restoredVm = xapi.getObject(restoredId)
try {