@@ -1171,28 +1171,40 @@ protected void runInContext() {
11711171 }
11721172
11731173 final Map <VirtualMachine , Backup .Metric > metrics = backupProvider .getBackupMetrics (dataCenter .getId (), new ArrayList <>(vms ));
1174- try {
1175- for (final VirtualMachine vm : metrics .keySet ()) {
1176- final Backup .Metric metric = metrics .get (vm );
1177- if (metric != null ) {
1178- // Sync out-of-band backups
1179- backupProvider .syncBackups (vm , metric );
1180- // Emit a usage event, update usage metric for the VM by the usage server
1181- UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_BACKUP_USAGE_METRIC , vm .getAccountId (),
1182- vm .getDataCenterId (), vm .getId (), "Backup-" + vm .getHostName () + "-" + vm .getUuid (),
1183- vm .getBackupOfferingId (), null , metric .getBackupSize (), metric .getDataSize (),
1184- Backup .class .getSimpleName (), vm .getUuid ());
1185- }
1186- }
1187- } catch (final Throwable e ) {
1188- LOG .error (String .format ("Failed to sync backup usage metrics and out-of-band backups due to: [%s]." , e .getMessage ()), e );
1189- }
1174+ syncBackupMetrics (backupProvider , metrics );
11901175 }
11911176 } catch (final Throwable t ) {
11921177 LOG .error (String .format ("Error trying to run backup-sync background task due to: [%s]." , t .getMessage ()), t );
11931178 }
11941179 }
11951180
1181+ /**
1182+ * Tries to sync the VM backups. If one backup synchronization fails, only this VM backups are skipped, and the entire process does not stop.
1183+ */
1184+ private void syncBackupMetrics (final BackupProvider backupProvider , final Map <VirtualMachine , Backup .Metric > metrics ) {
1185+ for (final VirtualMachine vm : metrics .keySet ()) {
1186+ tryToSyncVMBackups (backupProvider , metrics , vm );
1187+ }
1188+ }
1189+
1190+ private void tryToSyncVMBackups (BackupProvider backupProvider , Map <VirtualMachine , Backup .Metric > metrics , VirtualMachine vm ) {
1191+ try {
1192+ final Backup .Metric metric = metrics .get (vm );
1193+ if (metric != null ) {
1194+ LOG .debug (String .format ("Trying to sync backups of VM [%s] using backup provider [%s]." , vm .getUuid (), backupProvider .getName ()));
1195+ // Sync out-of-band backups
1196+ backupProvider .syncBackups (vm , metric );
1197+ // Emit a usage event, update usage metric for the VM by the usage server
1198+ UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_BACKUP_USAGE_METRIC , vm .getAccountId (),
1199+ vm .getDataCenterId (), vm .getId (), "Backup-" + vm .getHostName () + "-" + vm .getUuid (),
1200+ vm .getBackupOfferingId (), null , metric .getBackupSize (), metric .getDataSize (),
1201+ Backup .class .getSimpleName (), vm .getUuid ());
1202+ }
1203+ } catch (final Exception e ) {
1204+ 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 );
1205+ }
1206+ }
1207+
11961208 @ Override
11971209 public Long getDelay () {
11981210 return BackupSyncPollingInterval .value () * 1000L ;
0 commit comments