feat(backup): DeltaBackupWriter can handle any type of vhd

This commit is contained in:
Florent Beauchamp
2021-11-24 17:18:06 +01:00
committed by Julien Fontanet
parent 9cacb92c2c
commit 8c3b452c0d

View File

@@ -3,7 +3,7 @@ const map = require('lodash/map.js')
const mapValues = require('lodash/mapValues.js') const mapValues = require('lodash/mapValues.js')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js') const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const { asyncMap } = require('@xen-orchestra/async-map') const { asyncMap } = require('@xen-orchestra/async-map')
const { chainVhd, checkVhdChain, VhdFile } = require('vhd-lib') const { chainVhd, checkVhdChain, openVhd, VhdAbstract } = require('vhd-lib')
const { createLogger } = require('@xen-orchestra/log') const { createLogger } = require('@xen-orchestra/log')
const { dirname } = require('path') const { dirname } = require('path')
@@ -16,6 +16,7 @@ const { MixinBackupWriter } = require('./_MixinBackupWriter.js')
const { AbstractDeltaWriter } = require('./_AbstractDeltaWriter.js') const { AbstractDeltaWriter } = require('./_AbstractDeltaWriter.js')
const { checkVhd } = require('./_checkVhd.js') const { checkVhd } = require('./_checkVhd.js')
const { packUuid } = require('./_packUuid.js') const { packUuid } = require('./_packUuid.js')
const { Disposable } = require('promise-toolbox')
const { warn } = createLogger('xo:backups:DeltaBackupWriter') const { warn } = createLogger('xo:backups:DeltaBackupWriter')
@@ -37,13 +38,13 @@ exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(Ab
await asyncMap(vhds, async path => { await asyncMap(vhds, async path => {
try { try {
await checkVhdChain(handler, path) await checkVhdChain(handler, path)
await Disposable.use(
const vhd = new VhdFile(handler, path) openVhd(handler, path),
await vhd.readHeaderAndFooter() vhd => (found = found || vhd.footer.uuid.equals(packUuid(baseUuid)))
found = found || vhd.footer.uuid.equals(packUuid(baseUuid)) )
} catch (error) { } catch (error) {
warn('checkBaseVdis', { error }) warn('checkBaseVdis', { error })
await ignoreErrors.call(handler.unlink(path)) await ignoreErrors.call(VhdAbstract.unlink(handler, path))
} }
}) })
} catch (error) { } catch (error) {
@@ -200,11 +201,11 @@ exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(Ab
} }
// set the correct UUID in the VHD // set the correct UUID in the VHD
const vhd = new VhdFile(handler, path) await Disposable.use(openVhd(handler, path), async vhd => {
await vhd.readHeaderAndFooter() vhd.footer.uuid = packUuid(vdi.uuid)
vhd.footer.uuid = packUuid(vdi.uuid) await vhd.readBlockAllocationTable() // required by writeFooter()
await vhd.readBlockAllocationTable() // required by writeFooter() await vhd.writeFooter()
await vhd.writeFooter() })
}) })
) )
return { return {