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) {
List<String> volumePaths = new ArrayList<>();
for (VolumeVO volume : volumes) {
StoragePoolVO storagePool = primaryDataStoreDao.findById(volume.getPoolId());
Expand All @@ -259,8 +259,22 @@ 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()));
}
continue;
}
}

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

return volumePaths;
}

Expand Down
Loading