feat(backups/RemoteAdapter): new method deleteVmBackups()

It's usually best to delete multiple backups at once instead of one by one because it allows some optimizations, for instance when merging unused VHDs.

This was already possible in private methods but not exposed in the public API.
This commit is contained in:
Julien Fontanet
2021-12-15 16:34:35 +01:00
parent cf9f0da6e5
commit 7e302fd1cb

View File

@@ -3,6 +3,7 @@ const Disposable = require('promise-toolbox/Disposable.js')
const fromCallback = require('promise-toolbox/fromCallback.js')
const fromEvent = require('promise-toolbox/fromEvent.js')
const pDefer = require('promise-toolbox/defer.js')
const groupBy = require('lodash/groupBy.js')
const { dirname, join, normalize, resolve } = require('path')
const { createLogger } = require('@xen-orchestra/log')
const { Constants, createVhdDirectoryFromStream, openVhd, VhdAbstract, VhdSynthetic } = require('vhd-lib')
@@ -243,17 +244,14 @@ class RemoteAdapter {
)
}
async deleteVmBackup(filename) {
const metadata = JSON.parse(String(await this._handler.readFile(filename)))
metadata._filename = filename
deleteVmBackup(file) {
return this.deleteVmBackups([file])
}
if (metadata.mode === 'delta') {
await this.deleteDeltaVmBackups([metadata])
} else if (metadata.mode === 'full') {
await this.deleteFullVmBackups([metadata])
} else {
throw new Error(`no deleter for backup mode ${metadata.mode}`)
}
async deleteVmBackups(files) {
const metadatas = groupBy(await asyncMap(files, file => this.readVmBackupMetadata(file)), 'mode')
await Promise.all([this.deleteDeltaVmBackups(metadatas.delta), this.deleteFullVmBackups(metadatas.full)])
}
getDisk = Disposable.factory(this.getDisk)