diff --git a/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java b/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java index 5da3514b848..ddcb15f6151 100644 --- a/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java @@ -1171,28 +1171,40 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager { } final Map metrics = backupProvider.getBackupMetrics(dataCenter.getId(), new ArrayList<>(vms)); - try { - for (final VirtualMachine vm : metrics.keySet()) { - final Backup.Metric metric = metrics.get(vm); - if (metric != null) { - // Sync out-of-band backups - backupProvider.syncBackups(vm, metric); - // Emit a usage event, update usage metric for the VM by the usage server - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_BACKUP_USAGE_METRIC, vm.getAccountId(), - vm.getDataCenterId(), vm.getId(), "Backup-" + vm.getHostName() + "-" + vm.getUuid(), - vm.getBackupOfferingId(), null, metric.getBackupSize(), metric.getDataSize(), - Backup.class.getSimpleName(), vm.getUuid()); - } - } - } catch (final Throwable e) { - LOG.error(String.format("Failed to sync backup usage metrics and out-of-band backups due to: [%s].", e.getMessage()), e); - } + syncBackupMetrics(backupProvider, metrics); } } catch (final Throwable t) { LOG.error(String.format("Error trying to run backup-sync background task due to: [%s].", t.getMessage()), t); } } + /** + * Tries to sync the VM backups. If one backup synchronization fails, only this VM backups are skipped, and the entire process does not stop. + */ + private void syncBackupMetrics(final BackupProvider backupProvider, final Map metrics) { + for (final VirtualMachine vm : metrics.keySet()) { + tryToSyncVMBackups(backupProvider, metrics, vm); + } + } + + private void tryToSyncVMBackups(BackupProvider backupProvider, Map metrics, VirtualMachine vm) { + try { + final Backup.Metric metric = metrics.get(vm); + if (metric != null) { + LOG.debug(String.format("Trying to sync backups of VM [%s] using backup provider [%s].", vm.getUuid(), backupProvider.getName())); + // Sync out-of-band backups + backupProvider.syncBackups(vm, metric); + // Emit a usage event, update usage metric for the VM by the usage server + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_BACKUP_USAGE_METRIC, vm.getAccountId(), + vm.getDataCenterId(), vm.getId(), "Backup-" + vm.getHostName() + "-" + vm.getUuid(), + vm.getBackupOfferingId(), null, metric.getBackupSize(), metric.getDataSize(), + Backup.class.getSimpleName(), vm.getUuid()); + } + } catch (final Exception e) { + LOG.error(String.format("Failed to sync backup usage metrics and out-of-band backups of VM [%s] due to: [%s].", vm.getUuid(), e.getMessage()), e); + } + } + @Override public Long getDelay() { return BackupSyncPollingInterval.value() * 1000L;