@xen-orchestra/backups 0.67.1 → 0.67.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ import pickBy from 'lodash/pickBy.js'
11
11
  import { defer } from 'golike-defer'
12
12
  import { NegativeDisk } from '@xen-orchestra/disk-transform'
13
13
  import { openDiskChain } from './disks/openDiskChain.mjs'
14
+ import { resetVmOtherConfig } from './_otherConfig.mjs'
14
15
 
15
16
  const { debug, info, warn } = createLogger('xo:backups:importVmBackup')
16
17
  async function resolveUuid(xapi, cache, uuid, type) {
@@ -270,6 +271,7 @@ export class ImportVmBackup {
270
271
  `${metadata.vm.name_label} (${formatFilenameDate(metadata.timestamp)})`
271
272
  ),
272
273
  xapi.call('VM.set_name_description', vmRef, desc),
274
+ resetVmOtherConfig(xapi, vmRef),
273
275
  ])
274
276
 
275
277
  return {
package/_otherConfig.mjs CHANGED
@@ -70,7 +70,8 @@ export async function getVmDeltaChainLength(xapi, vmRef) {
70
70
 
71
71
  /**
72
72
  *
73
- * Reset the other_config field of a VM and its VDIs
73
+ * Reset the other_config field related to backups of a VM and its VDIs
74
+ *
74
75
  *
75
76
  * @param {Xapi} xapi
76
77
  * @param {String} vmRef
@@ -1,5 +1,6 @@
1
1
  import assert from 'node:assert'
2
2
  import groupBy from 'lodash/groupBy.js'
3
+ import { createLogger } from '@xen-orchestra/log'
3
4
  import ignoreErrors from 'promise-toolbox/ignoreErrors'
4
5
  import { asyncMap } from '@xen-orchestra/async-map'
5
6
  import { decorateMethodsWith } from '@vates/decorate-with'
@@ -17,6 +18,8 @@ import {
17
18
  setVmOtherConfig,
18
19
  } from '../../_otherConfig.mjs'
19
20
 
21
+ const { warn } = createLogger('xo:backups:AbstractXapi')
22
+
20
23
  export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
21
24
  constructor({
22
25
  config,
@@ -255,28 +258,47 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
255
258
  return
256
259
  }
257
260
  const vdis = snapshotPerDatetime[datetime]
258
- let vmRef
261
+ let vm
259
262
  // if there is an attached VM => destroy the VM (Non CBT backups)
260
263
  for (const vdi of vdis) {
261
264
  const vbds = vdi.$VBDs.filter(({ $VM }) => $VM.is_control_domain === false)
262
265
  if (vbds.length > 0) {
263
266
  // only one VM linked to this vdi
264
267
  // this will throw error for VDI still attached to control domain
268
+ // since we won't be able to remove an attached VDI
265
269
  assert.strictEqual(vbds.length, 1, 'VDI must be free or attached to exactly one VM')
266
- const vm = vbds[0].$VM
267
- assert.strictEqual(vm.is_a_snapshot, true, `VM must be a snapshot`) // don't delete a VM (especially a control domain)
268
-
269
- const vmRefVdi = vm.$ref
270
- // same vm than other vdi of the same batch
271
- assert.ok(
272
- vmRef === undefined || vmRef === vmRefVdi,
273
- '_removeUnusedSnapshots don t handle vdi related to multiple VMs '
274
- )
275
- vmRef = vmRefVdi
270
+ const vdiVm = vbds[0].$VM
271
+ if (!vdiVm.is_a_snapshot) {
272
+ // don't delete a VM (especially a control domain)
273
+ warn(
274
+ `VM ${vdiVm.uuid} (${vdiVm.name_label}) linked to VDI ${vdi.uuid} (${vdi.name_label}) should be a snapshot`
275
+ )
276
+ throw new Error(`VM must be a snapshot`)
277
+ }
278
+ if (vm !== undefined && vm.$ref !== vdiVm.$ref) {
279
+ // this VDI is attached to another VM than the other vdi of
280
+ // this batch
281
+ // in doubt, do not delete anything
282
+ warn("_removeUnusedSnapshots don't handle vdi related to multiple VMs ", {
283
+ vm1: {
284
+ label: vm.name_label,
285
+ id: vm.$id,
286
+ },
287
+ vm2: {
288
+ label: vdiVm.name_label,
289
+ id: vdiVm.$id,
290
+ },
291
+ vdis: vdis.map(({ name_label, $id }) => ({ name_label, $id })),
292
+ })
293
+ throw new Error(
294
+ `_removeUnusedSnapshots don't handle vdi related to multiple VMs ${vm.name_label} and ${vdiVm.name_label}`
295
+ )
296
+ }
297
+ vm = vdiVm
276
298
  }
277
299
  }
278
- if (vmRef !== undefined) {
279
- return xapi.VM_destroy(vmRef)
300
+ if (vm?.$ref !== undefined) {
301
+ return xapi.VM_destroy(vm.$ref)
280
302
  } else {
281
303
  return asyncMap(
282
304
  vdis.map(async ({ $ref }) => {
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/vatesfr/xen-orchestra.git"
10
10
  },
11
- "version": "0.67.1",
11
+ "version": "0.67.2",
12
12
  "engines": {
13
13
  "node": ">=14.18"
14
14
  },
@@ -29,10 +29,10 @@
29
29
  "@vates/nbd-client": "^3.2.2",
30
30
  "@vates/parse-duration": "^0.1.1",
31
31
  "@xen-orchestra/async-map": "^0.1.2",
32
- "@xen-orchestra/disk-transform": "^1.2.0",
32
+ "@xen-orchestra/disk-transform": "^1.2.1",
33
33
  "@xen-orchestra/fs": "^4.6.5",
34
34
  "@xen-orchestra/log": "^0.7.1",
35
- "@xen-orchestra/qcow2": "^1.1.0",
35
+ "@xen-orchestra/qcow2": "^1.1.1",
36
36
  "@xen-orchestra/template": "^0.1.0",
37
37
  "app-conf": "^3.0.0",
38
38
  "compare-versions": "^6.0.0",
@@ -51,8 +51,8 @@
51
51
  "tar": "^6.1.15",
52
52
  "uuid": "^9.0.0",
53
53
  "value-matcher": "^0.2.0",
54
- "vhd-lib": "^4.14.5",
55
- "xen-api": "^4.7.5",
54
+ "vhd-lib": "^4.14.6",
55
+ "xen-api": "^4.7.6",
56
56
  "yazl": "^2.5.1"
57
57
  },
58
58
  "devDependencies": {
@@ -62,7 +62,7 @@
62
62
  "tmp": "^0.2.1"
63
63
  },
64
64
  "peerDependencies": {
65
- "@xen-orchestra/xapi": "^8.6.1"
65
+ "@xen-orchestra/xapi": "^8.6.3"
66
66
  },
67
67
  "license": "AGPL-3.0-or-later",
68
68
  "author": {