Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager;

import com.cloud.utils.UuidUtils;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.backup.Backup;
Expand Down Expand Up @@ -906,7 +907,9 @@ public Pair<Boolean, String> restoreVMToDifferentLocation(String restorePointId,
if (restoreLocation == null) {
restoreLocation = RESTORE_VM_SUFFIX + UUID.randomUUID().toString();
}
final String datastoreId = dataStoreUuid.replace("-","");
final String datastoreId = UuidUtils.isUuid(dataStoreUuid) ?
dataStoreUuid.replace("-","") :
dataStoreUuid;
Comment on lines +910 to +912
final List<String> cmds = Arrays.asList(
"$points = Get-VBRRestorePoint",
String.format("foreach($point in $points) { if ($point.Id -eq '%s') { $restorePoint = $point; break; } }", restorePointId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,8 @@ public boolean restoreBackupToVM(final Long backupId, final Long vmId) throws Cl
if (!"nas".equals(offering.getProvider())) {
Pair<HostVO, StoragePoolVO> restoreInfo = getRestoreVolumeHostAndDatastore(vm);
host = restoreInfo.first().getPrivateIpAddress();
dataStore = restoreInfo.second().getUuid();
String[] datastorePossibleValues = getDatastorePossibleValues(restoreInfo.second());
dataStore = datastorePossibleValues[0];
}
result = backupProvider.restoreBackupToVM(vm, backup, host, dataStore);

Expand Down Expand Up @@ -1481,7 +1482,7 @@ public boolean restoreBackupVolumeAndAttachToVM(final String backedUpVolumeUuid,
logger.debug(String.format("Trying to restore volume using host private IP address: [%s].", host.getPrivateIpAddress()));

String[] hostPossibleValues = {host.getPrivateIpAddress(), host.getName()};
String[] datastoresPossibleValues = {datastore.getUuid(), datastore.getName()};
String[] datastoresPossibleValues = getDatastorePossibleValues(datastore);

Pair<Boolean, String> result = restoreBackedUpVolume(backupVolumeInfo, backup, backupProvider, hostPossibleValues, datastoresPossibleValues, vm);

Expand All @@ -1496,6 +1497,20 @@ public boolean restoreBackupVolumeAndAttachToVM(final String backedUpVolumeUuid,
return true;
}

/**
* For VMFS datastores, the identifier to be used for Veeam restore is the datastore name.
* Otherwise, possible values are the datastore UUID and the datastore name..
*/
protected String[] getDatastorePossibleValues(StoragePoolVO datastore) {
if (datastore == null) {
return new String[0];
}
if (Storage.StoragePoolType.VMFS == datastore.getPoolType()) {
return new String[]{datastore.getName()};
}
return new String[]{datastore.getUuid(), datastore.getName()};
}

protected Pair<Boolean, String> restoreBackedUpVolume(final Backup.VolumeInfo backupVolumeInfo, final BackupVO backup,
BackupProvider backupProvider, String[] hostPossibleValues, String[] datastoresPossibleValues, VMInstanceVO vm) {
Pair<Boolean, String> result = new Pair<>(false, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2242,4 +2242,33 @@ public void testRestoreBackupVolumeMismatch() {
verify(vmInstanceDao, times(1)).findByIdIncludingRemoved(vmId);
verify(volumeDao, times(1)).findByInstance(vmId);
}

@Test
public void testGetDatastorePossibleValuesNFS() {
String poolName = "NFS-Pool-Name";
String poolUuid = UUID.randomUUID().toString();

StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
when(pool.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
when(pool.getName()).thenReturn(poolName);
when(pool.getUuid()).thenReturn(poolUuid);

String[] datastorePossibleValues = backupManager.getDatastorePossibleValues(pool);
Assert.assertEquals(2, datastorePossibleValues.length);
Assert.assertEquals(poolUuid, datastorePossibleValues[0]);
Assert.assertEquals(poolName, datastorePossibleValues[1]);
}

@Test
public void testGetDatastorePossibleValuesVSAN() {
String poolName = "VSAN-Pool-Name";

StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
when(pool.getPoolType()).thenReturn(Storage.StoragePoolType.VMFS);
when(pool.getName()).thenReturn(poolName);
Comment on lines +2262 to +2268

String[] datastorePossibleValues = backupManager.getDatastorePossibleValues(pool);
Assert.assertEquals(1, datastorePossibleValues.length);
Assert.assertEquals(poolName, datastorePossibleValues[0]);
}
}
Loading