feat(backups): lock VM dir during backup (#5746)

May fix xoa-support#3387
This commit is contained in:
Julien Fontanet
2021-04-26 09:23:20 +02:00
committed by GitHub
parent a344b3b76d
commit 29fd2ff5e9
4 changed files with 22 additions and 4 deletions

View File

@@ -3,8 +3,9 @@ const findLast = require('lodash/findLast.js')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const keyBy = require('lodash/keyBy.js')
const mapValues = require('lodash/mapValues.js')
const { asyncMap } = require('@xen-orchestra/async-map')
const { asyncMap, asyncMapSettled } = require('@xen-orchestra/async-map')
const { createLogger } = require('@xen-orchestra/log')
const { defer } = require('golike-defer')
const { formatDateTime } = require('@xen-orchestra/xapi')
const { DeltaBackupWriter } = require('./writers/DeltaBackupWriter.js')
@@ -321,14 +322,18 @@ exports.VmBackup = class VmBackup {
this._fullVdisRequired = fullVdisRequired
}
async run() {
run = defer(this.run)
async run($defer) {
const settings = this._settings
assert(
!settings.offlineBackup || settings.snapshotRetention === 0,
'offlineBackup is not compatible with snapshotRetention'
)
await asyncMap(this._writers, writer => writer.beforeBackup())
await asyncMapSettled(this._writers, async writer => {
await writer.beforeBackup()
$defer(() => writer.afterBackup())
})
await this._fetchJobSnapshots()

View File

@@ -5,4 +5,6 @@ exports.AbstractWriter = class AbstractWriter {
}
beforeBackup() {}
afterBackup() {}
}

View File

@@ -11,15 +11,25 @@ exports.MixinBackupWriter = (BaseClass = Object) =>
this._adapter = rest.backup.remoteAdapters[remoteId]
this._remoteId = remoteId
this._lock = undefined
}
async beforeBackup() {
const adapter = this._adapter
const vmBackupDir = getVmBackupDir(this._backup.vm.uuid)
try {
await this._adapter.cleanVm(getVmBackupDir(this._backup.vm.uuid), { remove: true, merge: true, onLog: debug })
await adapter.cleanVm(vmBackupDir, { remove: true, merge: true, onLog: debug })
} catch (error) {
if (error?.code !== 'ENOENT') {
throw error
}
}
this._lock = await adapter.handler.lock(vmBackupDir)
}
async afterBackup() {
await this._lock.dispose()
}
}

View File

@@ -11,6 +11,7 @@
- [NFS remotes] Don't force version 3 by default (PR [#5725](https://github.com/vatesfr/xen-orchestra/pull/5725))
- [Template] Ability to create a template from a snapshot [#4891](https://github.com/vatesfr/xen-orchestra/issues/4891) (PR [#5736](https://github.com/vatesfr/xen-orchestra/pull/5736))
- [PIF] Automatically reconfigure management PIF on host case of IP address change to avoid connection loss [#5730](https://github.com/vatesfr/xen-orchestra/issues/5730) (PR [#5745](https://github.com/vatesfr/xen-orchestra/pull/5745))
- [Backup] Lock VM directory during backup to avoid race conditions (PR [#5746](https://github.com/vatesfr/xen-orchestra/pull/5746))
### Bug fixes