Skip to content

Commit

Permalink
fix(backups,xo-server): don't backup VMs created by Health Check
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp authored and julien-f committed Nov 29, 2023
1 parent 87a9fbe commit a5acc7d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
15 changes: 12 additions & 3 deletions @xen-orchestra/backups/ImportVmBackup.mjs
Expand Up @@ -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')
}
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion packages/xo-server/src/xo-mixins/backups-ng/index.mjs
Expand Up @@ -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 {
Expand Down

0 comments on commit a5acc7d

Please sign in to comment.