@xen-orchestra/backups 0.28.0 → 0.29.0

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.
package/Backup.js CHANGED
@@ -43,6 +43,7 @@ const DEFAULT_VM_SETTINGS = {
43
43
  offlineSnapshot: false,
44
44
  snapshotRetention: 0,
45
45
  timeout: 0,
46
+ useNbd: false,
46
47
  unconditionalSnapshot: false,
47
48
  vmTimeout: 0,
48
49
  }
package/RemoteAdapter.js CHANGED
@@ -76,14 +76,16 @@ const debounceResourceFactory = factory =>
76
76
  }
77
77
 
78
78
  class RemoteAdapter {
79
- constructor(handler, { debounceResource = res => res, dirMode, vhdDirectoryCompression, useGetDiskLegacy=false } = {}) {
79
+ constructor(
80
+ handler,
81
+ { debounceResource = res => res, dirMode, vhdDirectoryCompression, useGetDiskLegacy = false } = {}
82
+ ) {
80
83
  this._debounceResource = debounceResource
81
84
  this._dirMode = dirMode
82
85
  this._handler = handler
83
86
  this._vhdDirectoryCompression = vhdDirectoryCompression
84
87
  this._readCacheListVmBackups = synchronized.withKey()(this._readCacheListVmBackups)
85
88
  this._useGetDiskLegacy = useGetDiskLegacy
86
-
87
89
  }
88
90
 
89
91
  get handler() {
@@ -324,9 +326,7 @@ class RemoteAdapter {
324
326
  return this.#useVhdDirectory()
325
327
  }
326
328
 
327
-
328
329
  async *#getDiskLegacy(diskId) {
329
-
330
330
  const RE_VHDI = /^vhdi(\d+)$/
331
331
  const handler = this._handler
332
332
 
@@ -358,8 +358,8 @@ class RemoteAdapter {
358
358
  }
359
359
 
360
360
  async *getDisk(diskId) {
361
- if(this._useGetDiskLegacy){
362
- yield * this.#getDiskLegacy(diskId)
361
+ if (this._useGetDiskLegacy) {
362
+ yield* this.#getDiskLegacy(diskId)
363
363
  return
364
364
  }
365
365
  const handler = this._handler
@@ -659,9 +659,8 @@ class RemoteAdapter {
659
659
  return path
660
660
  }
661
661
 
662
- async writeVhd(path, input, { checksum = true, validator = noop, writeBlockConcurrency } = {}) {
662
+ async writeVhd(path, input, { checksum = true, validator = noop, writeBlockConcurrency, nbdClient } = {}) {
663
663
  const handler = this._handler
664
-
665
664
  if (this.#useVhdDirectory()) {
666
665
  const dataPath = `${dirname(path)}/data/${uuidv4()}.vhd`
667
666
  await createVhdDirectoryFromStream(handler, dataPath, input, {
@@ -671,6 +670,7 @@ class RemoteAdapter {
671
670
  await input.task
672
671
  return validator.apply(this, arguments)
673
672
  },
673
+ nbdClient,
674
674
  })
675
675
  await VhdAbstract.createAlias(handler, path, dataPath)
676
676
  } else {
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.28.0",
11
+ "version": "0.29.0",
12
12
  "engines": {
13
13
  "node": ">=14.6"
14
14
  },
@@ -20,12 +20,13 @@
20
20
  "@vates/cached-dns.lookup": "^1.0.0",
21
21
  "@vates/compose": "^2.1.0",
22
22
  "@vates/decorate-with": "^2.0.0",
23
- "@vates/disposable": "^0.1.1",
23
+ "@vates/disposable": "^0.1.2",
24
24
  "@vates/fuse-vhd": "^1.0.0",
25
+ "@vates/nbd-client": "*",
25
26
  "@vates/parse-duration": "^0.1.1",
26
27
  "@xen-orchestra/async-map": "^0.1.2",
27
- "@xen-orchestra/fs": "^3.1.0",
28
- "@xen-orchestra/log": "^0.3.0",
28
+ "@xen-orchestra/fs": "^3.2.0",
29
+ "@xen-orchestra/log": "^0.4.0",
29
30
  "@xen-orchestra/template": "^0.1.0",
30
31
  "compare-versions": "^5.0.1",
31
32
  "d3-time-format": "^3.0.0",
@@ -40,7 +41,7 @@
40
41
  "promise-toolbox": "^0.21.0",
41
42
  "proper-lockfile": "^4.1.2",
42
43
  "uuid": "^9.0.0",
43
- "vhd-lib": "^4.1.0",
44
+ "vhd-lib": "^4.1.1",
44
45
  "yazl": "^2.5.1"
45
46
  },
46
47
  "devDependencies": {
@@ -48,7 +49,7 @@
48
49
  "tmp": "^0.2.1"
49
50
  },
50
51
  "peerDependencies": {
51
- "@xen-orchestra/xapi": "^1.5.0"
52
+ "@xen-orchestra/xapi": "^1.5.2"
52
53
  },
53
54
  "license": "AGPL-3.0-or-later",
54
55
  "author": {
@@ -19,8 +19,9 @@ const { AbstractDeltaWriter } = require('./_AbstractDeltaWriter.js')
19
19
  const { checkVhd } = require('./_checkVhd.js')
20
20
  const { packUuid } = require('./_packUuid.js')
21
21
  const { Disposable } = require('promise-toolbox')
22
+ const NbdClient = require('@vates/nbd-client')
22
23
 
23
- const { warn } = createLogger('xo:backups:DeltaBackupWriter')
24
+ const { debug, warn } = createLogger('xo:backups:DeltaBackupWriter')
24
25
 
25
26
  exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(AbstractDeltaWriter) {
26
27
  async checkBaseVdis(baseUuidToSrcVdi) {
@@ -199,12 +200,30 @@ exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(Ab
199
200
  await checkVhd(handler, parentPath)
200
201
  }
201
202
 
203
+ const vdiRef = vm.$xapi.getObject(vdi.uuid).$ref
204
+
205
+ let nbdClient
206
+ if (!this._backup.config.useNbd) {
207
+ // get nbd if possible
208
+ try {
209
+ // this will always take the first host in the list
210
+ const [nbdInfo] = await vm.$xapi.call('VDI.get_nbd_info', vdiRef)
211
+ nbdClient = new NbdClient(nbdInfo)
212
+ await nbdClient.connect()
213
+ debug(`got nbd connection `, { vdi: vdi.uuid })
214
+ } catch (error) {
215
+ nbdClient = undefined
216
+ debug(`can't connect to nbd server or no server available`, { error })
217
+ }
218
+ }
219
+
202
220
  await adapter.writeVhd(path, deltaExport.streams[`${id}.vhd`], {
203
221
  // no checksum for VHDs, because they will be invalidated by
204
222
  // merges and chainings
205
223
  checksum: false,
206
224
  validator: tmpPath => checkVhd(handler, tmpPath),
207
225
  writeBlockConcurrency: this._backup.config.writeBlockConcurrency,
226
+ nbdClient,
208
227
  })
209
228
 
210
229
  if (isDelta) {