diff --git a/CHANGELOG.md b/CHANGELOG.md index ac2337445..8b68d91ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - [New VM] Selecting multiple VMs and clicking Create then Cancel used to redirect to Home [#3268](https://github.com/vatesfr/xen-orchestra/issues/3268) (PR [#3371](https://github.com/vatesfr/xen-orchestra/pull/3371)) - [Remotes] `cannot read 'properties' of undefined` error (PR [#3382](https://github.com/vatesfr/xen-orchestra/pull/3382)) - [Servers] Various issues when adding a new server [#3385](https://github.com/vatesfr/xen-orchestra/issues/3385) (PR [#3388](https://github.com/vatesfr/xen-orchestra/pull/3388)) +- [Backup NG] Always delete the correct old replications [#3391](https://github.com/vatesfr/xen-orchestra/issues/3391) (PR [#3394](https://github.com/vatesfr/xen-orchestra/pull/3394)) ### Released packages 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 3295d765d..b6975509b 100644 --- a/packages/xo-server/src/xo-mixins/backups-ng/index.js +++ b/packages/xo-server/src/xo-mixins/backups-ng/index.js @@ -104,6 +104,16 @@ type Metadata = MetadataDelta | MetadataFull const compareSnapshotTime = (a: Vm, b: Vm): number => a.snapshot_time < b.snapshot_time ? -1 : 1 +const getReplicatedVmDatetime = (vm: Vm) => { + const { + 'xo:backup:datetime': datetime = vm.name_label.slice(-17, -1), + } = vm.other_config + return datetime +} + +const compareReplicatedVmDatetime = (a: Vm, b: Vm): number => + getReplicatedVmDatetime(a) < getReplicatedVmDatetime(b) ? -1 : 1 + const compareTimestamp = (a: Metadata, b: Metadata): number => a.timestamp - b.timestamp @@ -183,9 +193,7 @@ const listReplicatedVms = ( } } - // the replicated VMs have been created from a snapshot, therefore we can use - // `snapshot_time` as the creation time - return values(vms).sort(compareSnapshotTime) + return values(vms).sort(compareReplicatedVmDatetime) } const importers: $Dict< @@ -762,6 +770,7 @@ export default class BackupNg { parentId: taskId, }, xapi._updateObjectMapProperty(vm, 'other_config', { + 'xo:backup:datetime': null, 'xo:backup:job': null, 'xo:backup:schedule': null, 'xo:backup:vm': null, @@ -873,6 +882,7 @@ export default class BackupNg { parentId: taskId, }, xapi._updateObjectMapProperty(snapshot, 'other_config', { + 'xo:backup:datetime': snapshot.snapshot_time, 'xo:backup:job': jobId, 'xo:backup:schedule': scheduleId, 'xo:backup:vm': vmUuid,