feat(xo-server#deleteMetadataBackup): use @xen-orchestra/backups lib (#5610)

This commit is contained in:
badrAZ 2021-02-24 11:38:27 +01:00 committed by GitHub
parent 5bd4c54ab6
commit 95c2944f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 19 deletions

View File

@ -0,0 +1,3 @@
exports.getMetadataBackupTypeFromId = function getMetadataBackupTypeFromId(backupId) {
return backupId.split('/')[0]
}

View File

@ -2,6 +2,7 @@
import asyncMap from '@xen-orchestra/async-map'
import createLogger from '@xen-orchestra/log'
import { fromEvent, ignoreErrors, timeout, using } from 'promise-toolbox'
import { getMetadataBackupTypeFromId } from '@xen-orchestra/backups/getMedataBackupTypeFromId'
import { parseDuration } from '@vates/parse-duration'
import { debounceWithKey, REMOVE_CACHE_ENTRY } from '../_pDebounceWithKey'
@ -874,29 +875,19 @@ export default class metadataBackup {
async deleteMetadataBackup(id: string) {
const app = this._app
const [remoteId, ...path] = id.split('/')
const metadataFolder = path.join('/')
const { proxy, url, options } = await app.getRemoteWithCredentials(remoteId)
if (proxy !== undefined) {
await app.callProxyMethod(proxy, 'backup.deleteMetadataBackup', {
backupId: metadataFolder,
remote: { url, options },
const backupId = path.join('/')
const remote = await app.getRemoteWithCredentials(remoteId)
if (remote.proxy !== undefined) {
await app.callProxyMethod(remote.proxy, 'backup.deleteMetadataBackup', {
backupId,
remote: { url: remote.url, options: remote.options },
})
} else {
const uuidReg = '\\w{8}(-\\w{4}){3}-\\w{12}'
const metadataDirReg = 'xo-(config|pool-metadata)-backups'
const timestampReg = '\\d{8}T\\d{6}Z'
const regexp = new RegExp(`^/?${uuidReg}/${metadataDirReg}/${uuidReg}(/${uuidReg})?/${timestampReg}`)
if (!regexp.test(id)) {
throw new Error(`The id (${id}) not correspond to a metadata folder`)
}
const handler = await app.getRemoteHandler(remoteId)
await handler.rmtree(metadataFolder)
await using(app.getBackupsRemoteAdapter(remote), adapter => adapter.deleteMetadataBackup(backupId))
}
if (path[0] === 'xo-config-backups') {
if (getMetadataBackupTypeFromId(backupId) === 'xo-config-backups') {
this._listXoMetadataBackups(REMOVE_CACHE_ENTRY, remoteId)
} else {
this._listPoolMetadataBackups(REMOVE_CACHE_ENTRY, remoteId)