From 1dfb50fefd7b933be79113cd453fa4941509eada Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 28 Mar 2019 18:10:05 +0100 Subject: [PATCH] feat(xo-server/backup): fullInterval setting (#4086) See #4083 --- .../src/xo-mixins/backups-ng/index.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/xo-server/src/xo-mixins/backups-ng/index.js b/packages/xo-server/src/xo-mixins/backups-ng/index.js index 051b48b8e..5f3cbcc64 100644 --- a/packages/xo-server/src/xo-mixins/backups-ng/index.js +++ b/packages/xo-server/src/xo-mixins/backups-ng/index.js @@ -140,6 +140,7 @@ const defaultSettings: Settings = { concurrency: 0, deleteFirst: false, exportRetention: 0, + fullInterval: 0, offlineSnapshot: false, reportWhen: 'failure', snapshotRetention: 0, @@ -475,10 +476,11 @@ const disableVmHighAvailability = async (xapi: Xapi, vm: Vm) => { // // - `other_config`: // - `xo:backup:datetime` = snapshot.snapshot_time (allow sorting replicated VMs) +// - `xo:backup:deltaChainLength` = n (number of delta copies/replicated since a full) +// - `xo:backup:exported` = 'true' (added at the end of the backup) // - `xo:backup:job` = job.id // - `xo:backup:schedule` = schedule.id // - `xo:backup:vm` = vm.uuid -// - `xo:backup:exported` = 'true' (added at the end of the backup) // // Attributes of created VMs: // @@ -937,6 +939,7 @@ export default class BackupNg { }, xapi._updateObjectMapProperty(vm, 'other_config', { 'xo:backup:datetime': null, + 'xo:backup:deltaChainLength': null, 'xo:backup:exported': null, 'xo:backup:job': null, 'xo:backup:schedule': null, @@ -1293,12 +1296,31 @@ export default class BackupNg { $defer.onSuccess.call(xapi, 'deleteVm', baseSnapshot) } + let deltaChainLength = 0 let fullVdisRequired await (async () => { if (baseSnapshot === undefined) { return } + let prevDeltaChainLength = +baseSnapshot.other_config[ + 'xo:backup:deltaChainLength' + ] + if (Number.isNaN(prevDeltaChainLength)) { + prevDeltaChainLength = 0 + } + deltaChainLength = prevDeltaChainLength + 1 + + const fullInterval = getSetting(settings, 'fullInterval', [ + vmUuid, + scheduleId, + '', + ]) + if (fullInterval !== 0 && fullInterval <= deltaChainLength) { + baseSnapshot = undefined + return + } + const fullRequired = { __proto__: null } const vdis: $Dict = getVmDisks(baseSnapshot) @@ -1626,6 +1648,15 @@ export default class BackupNg { ], noop // errors are handled in logs ) + + if (!isFull) { + ignoreErrors.call( + snapshot.update_other_config( + 'xo:backup:deltaChainLength', + String(deltaChainLength) + ) + ) + } } else { throw new Error(`no exporter for backup mode ${mode}`) }