Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public boolean takeBackup(final VirtualMachine vm) {
if (VirtualMachine.State.Stopped.equals(vm.getState())) {
List<VolumeVO> vmVolumes = volumeDao.findByInstance(vm.getId());
vmVolumes.sort(Comparator.comparing(Volume::getDeviceId));
List<String> volumePaths = getVolumePaths(vmVolumes);
List<String> volumePaths = getVolumePaths(vmVolumes, Collections.emptyList());
command.setVolumePaths(volumePaths);
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
restoreCommand.setBackupRepoAddress(backupRepository.getAddress());
restoreCommand.setMountOptions(backupRepository.getMountOptions());
restoreCommand.setVmName(vm.getName());
restoreCommand.setVolumePaths(getVolumePaths(volumes));
restoreCommand.setVolumePaths(getVolumePaths(volumes, backedVolumes));
restoreCommand.setVmExists(vm.getRemoved() == null);
restoreCommand.setVmState(vm.getState());

Expand All @@ -244,7 +244,7 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
return answer.getResult();
}

private List<String> getVolumePaths(List<VolumeVO> volumes) {
private List<String> getVolumePaths(List<VolumeVO> volumes, List<Backup.VolumeInfo> backedVolumes) {
List<String> volumePaths = new ArrayList<>();
for (VolumeVO volume : volumes) {
StoragePoolVO storagePool = primaryDataStoreDao.findById(volume.getPoolId());
Expand All @@ -259,7 +259,14 @@ private List<String> getVolumePaths(List<VolumeVO> volumes) {
} else {
volumePathPrefix = String.format("/mnt/%s", storagePool.getUuid());
}
volumePaths.add(String.format("%s/%s", volumePathPrefix, volume.getPath()));
backedVolumes.stream().filter(backedVolume -> backedVolume.getUuid().equals(volume.getUuid())).findFirst()
.ifPresent(backedVolume -> {
if (backedVolume.getPath() != null && !backedVolume.getPath().isEmpty()) {
volumePaths.add(String.format("%s/%s", volumePathPrefix, backedVolume.getPath()));
} else {
volumePaths.add(String.format("%s/%s", volumePathPrefix, volume.getPath()));
}
});
}
return volumePaths;
}
Expand Down
Loading