Skip to content

Commit d3ec27d

Browse files
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
1 parent 4d41b6b commit d3ec27d

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ private List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm) {
249249
return getClient(vm.getDataCenterId()).listRestorePoints(backupName, vm.getInstanceName());
250250
}
251251

252+
private Backup checkAndUpdateIfBackupEntryExistsForRestorePoint(List<Backup> backupsInDb, Backup.RestorePoint restorePoint, Backup.Metric metric) {
253+
for (final Backup backup : backupsInDb) {
254+
if (restorePoint.getId().equals(backup.getExternalId())) {
255+
if (metric != null) {
256+
LOG.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].",
257+
backup.getUuid(), backup.getExternalId(), backup.getSize(), backup.getProtectedSize(), metric.getBackupSize(), metric.getDataSize()));
258+
259+
((BackupVO) backup).setSize(metric.getBackupSize());
260+
((BackupVO) backup).setProtectedSize(metric.getDataSize());
261+
backupDao.update(backup.getId(), ((BackupVO) backup));
262+
}
263+
return backup;
264+
}
265+
}
266+
return null;
267+
}
268+
252269
@Override
253270
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
254271
List<Backup.RestorePoint> restorePoints = listRestorePoints(vm);
@@ -262,44 +279,33 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
262279
final List<Backup> backupsInDb = backupDao.listByVmId(null, vm.getId());
263280
final List<Long> removeList = backupsInDb.stream().map(InternalIdentity::getId).collect(Collectors.toList());
264281
for (final Backup.RestorePoint restorePoint : restorePoints) {
265-
boolean backupExists = false;
266-
for (final Backup backup : backupsInDb) {
267-
if (restorePoint.getId().equals(backup.getExternalId())) {
268-
backupExists = true;
269-
removeList.remove(backup.getId());
270-
if (metric != null) {
271-
LOG.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].",
272-
backup.getUuid(), backup.getExternalId(), backup.getSize(), backup.getProtectedSize(), metric.getBackupSize(), metric.getDataSize()));
273-
274-
((BackupVO) backup).setSize(metric.getBackupSize());
275-
((BackupVO) backup).setProtectedSize(metric.getDataSize());
276-
backupDao.update(backup.getId(), ((BackupVO) backup));
277-
}
278-
break;
282+
if (!(restorePoint.getId() == null || restorePoint.getType() == null || restorePoint.getCreated() == null)) {
283+
Backup existingBackupEntry = checkAndUpdateIfBackupEntryExistsForRestorePoint(backupsInDb, restorePoint, metric);
284+
if (existingBackupEntry != null) {
285+
removeList.remove(existingBackupEntry.getId());
286+
continue;
279287
}
288+
289+
BackupVO backup = new BackupVO();
290+
backup.setVmId(vm.getId());
291+
backup.setExternalId(restorePoint.getId());
292+
backup.setType(restorePoint.getType());
293+
backup.setDate(restorePoint.getCreated());
294+
backup.setStatus(Backup.Status.BackedUp);
295+
if (metric != null) {
296+
backup.setSize(metric.getBackupSize());
297+
backup.setProtectedSize(metric.getDataSize());
298+
}
299+
backup.setBackupOfferingId(vm.getBackupOfferingId());
300+
backup.setAccountId(vm.getAccountId());
301+
backup.setDomainId(vm.getDomainId());
302+
backup.setZoneId(vm.getDataCenterId());
303+
304+
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, "
305+
+ "domain_id: %s, zone_id: %s].", backup.getUuid(), backup.getVmId(), backup.getExternalId(), backup.getType(), backup.getDate(),
306+
backup.getBackupOfferingId(), backup.getAccountId(), backup.getDomainId(), backup.getZoneId()));
307+
backupDao.persist(backup);
280308
}
281-
if (backupExists) {
282-
continue;
283-
}
284-
BackupVO backup = new BackupVO();
285-
backup.setVmId(vm.getId());
286-
backup.setExternalId(restorePoint.getId());
287-
backup.setType(restorePoint.getType());
288-
backup.setDate(restorePoint.getCreated());
289-
backup.setStatus(Backup.Status.BackedUp);
290-
if (metric != null) {
291-
backup.setSize(metric.getBackupSize());
292-
backup.setProtectedSize(metric.getDataSize());
293-
}
294-
backup.setBackupOfferingId(vm.getBackupOfferingId());
295-
backup.setAccountId(vm.getAccountId());
296-
backup.setDomainId(vm.getDomainId());
297-
backup.setZoneId(vm.getDataCenterId());
298-
299-
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, "
300-
+ "domain_id: %s, zone_id: %s].", backup.getUuid(), backup.getVmId(), backup.getExternalId(), backup.getType(), backup.getDate(),
301-
backup.getBackupOfferingId(), backup.getAccountId(), backup.getDomainId(), backup.getZoneId()));
302-
backupDao.persist(backup);
303309
}
304310
for (final Long backupIdToRemove : removeList) {
305311
LOG.warn(String.format("Removing backup with ID: [%s].", backupIdToRemove));

0 commit comments

Comments
 (0)