From d3ec27dc7904362c0e098db7e3ca838e8afb0281 Mon Sep 17 00:00:00 2001 From: Harikrishna Date: Wed, 10 Aug 2022 16:59:10 +0530 Subject: [PATCH] Fixed Veeam listing restore points (#6555) Fixes issue #6465 where listing backup restore points are failing with Veeam version v11.0.1.1261. Though this version is not fully supported for backup and recovery, existing backups, restore points for the VMs can continue to work with the Veeam version v11.0.1.1261. I've created a separate ticket here to fully support the version #6554 --- .../backup/VeeamBackupProvider.java | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java index 072431c4a97..ca611487820 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java @@ -249,6 +249,23 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, return getClient(vm.getDataCenterId()).listRestorePoints(backupName, vm.getInstanceName()); } + private Backup checkAndUpdateIfBackupEntryExistsForRestorePoint(List backupsInDb, Backup.RestorePoint restorePoint, Backup.Metric metric) { + for (final Backup backup : backupsInDb) { + if (restorePoint.getId().equals(backup.getExternalId())) { + if (metric != null) { + LOG.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].", + backup.getUuid(), backup.getExternalId(), backup.getSize(), backup.getProtectedSize(), metric.getBackupSize(), metric.getDataSize())); + + ((BackupVO) backup).setSize(metric.getBackupSize()); + ((BackupVO) backup).setProtectedSize(metric.getDataSize()); + backupDao.update(backup.getId(), ((BackupVO) backup)); + } + return backup; + } + } + return null; + } + @Override public void syncBackups(VirtualMachine vm, Backup.Metric metric) { List restorePoints = listRestorePoints(vm); @@ -262,44 +279,33 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, final List backupsInDb = backupDao.listByVmId(null, vm.getId()); final List removeList = backupsInDb.stream().map(InternalIdentity::getId).collect(Collectors.toList()); for (final Backup.RestorePoint restorePoint : restorePoints) { - boolean backupExists = false; - for (final Backup backup : backupsInDb) { - if (restorePoint.getId().equals(backup.getExternalId())) { - backupExists = true; - removeList.remove(backup.getId()); - if (metric != null) { - LOG.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].", - backup.getUuid(), backup.getExternalId(), backup.getSize(), backup.getProtectedSize(), metric.getBackupSize(), metric.getDataSize())); - - ((BackupVO) backup).setSize(metric.getBackupSize()); - ((BackupVO) backup).setProtectedSize(metric.getDataSize()); - backupDao.update(backup.getId(), ((BackupVO) backup)); - } - break; + if (!(restorePoint.getId() == null || restorePoint.getType() == null || restorePoint.getCreated() == null)) { + Backup existingBackupEntry = checkAndUpdateIfBackupEntryExistsForRestorePoint(backupsInDb, restorePoint, metric); + if (existingBackupEntry != null) { + removeList.remove(existingBackupEntry.getId()); + continue; } - } - if (backupExists) { - continue; - } - BackupVO backup = new BackupVO(); - backup.setVmId(vm.getId()); - backup.setExternalId(restorePoint.getId()); - backup.setType(restorePoint.getType()); - backup.setDate(restorePoint.getCreated()); - backup.setStatus(Backup.Status.BackedUp); - if (metric != null) { - backup.setSize(metric.getBackupSize()); - backup.setProtectedSize(metric.getDataSize()); - } - backup.setBackupOfferingId(vm.getBackupOfferingId()); - backup.setAccountId(vm.getAccountId()); - backup.setDomainId(vm.getDomainId()); - backup.setZoneId(vm.getDataCenterId()); - LOG.debug(String.format("Creating a new entry in backups: [uuid: %s, vm_id: %s, external_id: %s, type: %s, date: %s, backup_offering_id: %s, account_id: %s, " - + "domain_id: %s, zone_id: %s].", backup.getUuid(), backup.getVmId(), backup.getExternalId(), backup.getType(), backup.getDate(), - backup.getBackupOfferingId(), backup.getAccountId(), backup.getDomainId(), backup.getZoneId())); - backupDao.persist(backup); + BackupVO backup = new BackupVO(); + backup.setVmId(vm.getId()); + backup.setExternalId(restorePoint.getId()); + backup.setType(restorePoint.getType()); + backup.setDate(restorePoint.getCreated()); + backup.setStatus(Backup.Status.BackedUp); + if (metric != null) { + backup.setSize(metric.getBackupSize()); + backup.setProtectedSize(metric.getDataSize()); + } + backup.setBackupOfferingId(vm.getBackupOfferingId()); + backup.setAccountId(vm.getAccountId()); + backup.setDomainId(vm.getDomainId()); + backup.setZoneId(vm.getDataCenterId()); + + LOG.debug(String.format("Creating a new entry in backups: [uuid: %s, vm_id: %s, external_id: %s, type: %s, date: %s, backup_offering_id: %s, account_id: %s, " + + "domain_id: %s, zone_id: %s].", backup.getUuid(), backup.getVmId(), backup.getExternalId(), backup.getType(), backup.getDate(), + backup.getBackupOfferingId(), backup.getAccountId(), backup.getDomainId(), backup.getZoneId())); + backupDao.persist(backup); + } } for (final Long backupIdToRemove : removeList) { LOG.warn(String.format("Removing backup with ID: [%s].", backupIdToRemove));