Skip to content

Commit 348c9ee

Browse files
committed
use the backed volume path to get the right location of backed volume to be restored
1 parent f51e048 commit 348c9ee

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public boolean takeBackup(final VirtualMachine vm) {
164164
if (VirtualMachine.State.Stopped.equals(vm.getState())) {
165165
List<VolumeVO> vmVolumes = volumeDao.findByInstance(vm.getId());
166166
vmVolumes.sort(Comparator.comparing(Volume::getDeviceId));
167-
List<String> volumePaths = getVolumePaths(vmVolumes);
167+
List<String> volumePaths = getVolumePaths(vmVolumes, Collections.emptyList());
168168
command.setVolumePaths(volumePaths);
169169
}
170170

@@ -215,7 +215,7 @@ private BackupVO createBackupObject(VirtualMachine vm, String backupPath) {
215215
public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
216216
List<Backup.VolumeInfo> backedVolumes = backup.getBackedUpVolumes();
217217
List<VolumeVO> volumes = backedVolumes.stream()
218-
.map(volume -> volumeDao.findByUuid(volume.getPath()))
218+
.map(volume -> volumeDao.findByUuid(volume.getUuid()))
219219
.sorted((v1, v2) -> Long.compare(v1.getDeviceId(), v2.getDeviceId()))
220220
.collect(Collectors.toList());
221221

@@ -229,7 +229,7 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
229229
restoreCommand.setBackupRepoAddress(backupRepository.getAddress());
230230
restoreCommand.setMountOptions(backupRepository.getMountOptions());
231231
restoreCommand.setVmName(vm.getName());
232-
restoreCommand.setVolumePaths(getVolumePaths(volumes));
232+
restoreCommand.setVolumePaths(getVolumePaths(volumes, backedVolumes));
233233
restoreCommand.setVmExists(vm.getRemoved() == null);
234234
restoreCommand.setVmState(vm.getState());
235235

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

247-
private List<String> getVolumePaths(List<VolumeVO> volumes) {
247+
private List<String> getVolumePaths(List<VolumeVO> volumes, List<Backup.VolumeInfo> backedVolumes) {
248248
List<String> volumePaths = new ArrayList<>();
249249
for (VolumeVO volume : volumes) {
250250
StoragePoolVO storagePool = primaryDataStoreDao.findById(volume.getPoolId());
@@ -259,7 +259,14 @@ private List<String> getVolumePaths(List<VolumeVO> volumes) {
259259
} else {
260260
volumePathPrefix = String.format("/mnt/%s", storagePool.getUuid());
261261
}
262-
volumePaths.add(String.format("%s/%s", volumePathPrefix, volume.getPath()));
262+
backedVolumes.stream().filter(backedVolume -> backedVolume.getUuid().equals(volume.getUuid())).findFirst()
263+
.ifPresent(backedVolume -> {
264+
if (backedVolume.getPath() != null && !backedVolume.getPath().isEmpty()) {
265+
volumePaths.add(String.format("%s/%s", volumePathPrefix, backedVolume.getPath()));
266+
} else {
267+
volumePaths.add(String.format("%s/%s", volumePathPrefix, volume.getPath()));
268+
}
269+
});
263270
}
264271
return volumePaths;
265272
}

0 commit comments

Comments
 (0)