Skip to content
Open
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 @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this returns empty list when backedVolumes is empty - passed in takeBackup() above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - fixed it.

List<String> volumePaths = new ArrayList<>();
for (VolumeVO volume : volumes) {
StoragePoolVO storagePool = primaryDataStoreDao.findById(volume.getPoolId());
Expand All @@ -259,8 +259,24 @@ private List<String> getVolumePaths(List<VolumeVO> volumes) {
} else {
volumePathPrefix = String.format("/mnt/%s", storagePool.getUuid());
}
boolean hasBackedVolumes = backedVolumes != null && !backedVolumes.isEmpty();
if (hasBackedVolumes) {
Optional<Backup.VolumeInfo> opt = backedVolumes.stream()
.filter(bv -> bv.getUuid().equals(volume.getUuid())).findFirst();
if (opt.isPresent()) {
Backup.VolumeInfo backedVolume = opt.get();
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()));
}
continue;
}
}

volumePaths.add(String.format("%s/%s", volumePathPrefix, volume.getPath()));
}

return volumePaths;
}

Expand Down
Loading