@@ -58,36 +58,38 @@ public Answer execute(RestoreBackupCommand command, LibvirtComputingResource ser
5858 String mountOptions = command .getMountOptions ();
5959 Boolean vmExists = command .isVmExists ();
6060 String diskType = command .getDiskType ();
61- List <String > volumePaths = command .getVolumePaths ();
61+ List <String > backedVolumeUUIDs = command .getBackupVolumesUUIDs ();
62+ List <String > restoreVolumePaths = command .getRestoreVolumePaths ();
6263 String restoreVolumeUuid = command .getRestoreVolumeUUID ();
6364
6465 String newVolumeId = null ;
6566 if (Objects .isNull (vmExists )) {
66- String volumePath = volumePaths .get (0 );
67+ String volumePath = restoreVolumePaths .get (0 );
6768 int lastIndex = volumePath .lastIndexOf ("/" );
6869 newVolumeId = volumePath .substring (lastIndex + 1 );
6970 restoreVolume (backupPath , backupRepoType , backupRepoAddress , volumePath , diskType , restoreVolumeUuid ,
7071 new Pair <>(vmName , command .getVmState ()));
7172 } else if (Boolean .TRUE .equals (vmExists )) {
72- restoreVolumesOfExistingVM (volumePaths , backupPath , backupRepoType , backupRepoAddress , mountOptions );
73+ restoreVolumesOfExistingVM (restoreVolumePaths , backedVolumeUUIDs , backupPath , backupRepoType , backupRepoAddress , mountOptions );
7374 } else {
74- restoreVolumesOfDestroyedVMs (volumePaths , vmName , backupPath , backupRepoType , backupRepoAddress , mountOptions );
75+ restoreVolumesOfDestroyedVMs (restoreVolumePaths , vmName , backupPath , backupRepoType , backupRepoAddress , mountOptions );
7576 }
7677
7778 return new BackupAnswer (command , true , newVolumeId );
7879 }
7980
80- private void restoreVolumesOfExistingVM (List <String > volumePaths , String backupPath ,
81- String backupRepoType , String backupRepoAddress , String mountOptions ) {
81+ private void restoreVolumesOfExistingVM (List <String > restoreVolumePaths , List < String > backedVolumesUUIDs , String backupPath ,
82+ String backupRepoType , String backupRepoAddress , String mountOptions ) {
8283 String diskType = "root" ;
8384 String mountDirectory = mountBackupDirectory (backupRepoAddress , backupRepoType );
8485 try {
85- for (int idx = 0 ; idx < volumePaths .size (); idx ++) {
86- String volumePath = volumePaths .get (idx );
87- Pair <String , String > bkpPathAndVolUuid = getBackupPath (mountDirectory , volumePath , backupPath , diskType , null );
86+ for (int idx = 0 ; idx < restoreVolumePaths .size (); idx ++) {
87+ String restoreVolumePath = restoreVolumePaths .get (idx );
88+ String backupVolumeUuid = backedVolumesUUIDs .get (idx );
89+ Pair <String , String > bkpPathAndVolUuid = getBackupPath (mountDirectory , null , backupPath , diskType , backupVolumeUuid );
8890 diskType = "datadisk" ;
8991 try {
90- replaceVolumeWithBackup (volumePath , bkpPathAndVolUuid .first ());
92+ replaceVolumeWithBackup (restoreVolumePath , bkpPathAndVolUuid .first ());
9193 } catch (IOException e ) {
9294 throw new CloudRuntimeException (String .format ("Unable to revert backup for volume [%s] due to [%s]." , bkpPathAndVolUuid .second (), e .getMessage ()), e );
9395 }
@@ -96,7 +98,6 @@ private void restoreVolumesOfExistingVM(List<String> volumePaths, String backupP
9698 unmountBackupDirectory (mountDirectory );
9799 deleteTemporaryDirectory (mountDirectory );
98100 }
99-
100101 }
101102
102103 private void restoreVolumesOfDestroyedVMs (List <String > volumePaths , String vmName , String backupPath ,
@@ -177,8 +178,7 @@ private void deleteTemporaryDirectory(String backupDirectory) {
177178
178179 private Pair <String , String > getBackupPath (String mountDirectory , String volumePath , String backupPath , String diskType , String volumeUuid ) {
179180 String bkpPath = String .format (FILE_PATH_PLACEHOLDER , mountDirectory , backupPath );
180- int lastIndex = volumePath .lastIndexOf (File .separator );
181- String volUuid = Objects .isNull (volumeUuid ) ? volumePath .substring (lastIndex + 1 ) : volumeUuid ;
181+ String volUuid = Objects .isNull (volumeUuid ) ? volumePath .substring (volumePath .lastIndexOf (File .separator ) + 1 ) : volumeUuid ;
182182 String backupFileName = String .format ("%s.%s.qcow2" , diskType .toLowerCase (Locale .ROOT ), volUuid );
183183 bkpPath = String .format (FILE_PATH_PLACEHOLDER , bkpPath , backupFileName );
184184 return new Pair <>(bkpPath , volUuid );
0 commit comments