@@ -88,10 +88,8 @@ private void restoreVolumesOfExistingVM(List<String> restoreVolumePaths, List<St
8888 String backupVolumeUuid = backedVolumesUUIDs .get (idx );
8989 Pair <String , String > bkpPathAndVolUuid = getBackupPath (mountDirectory , null , backupPath , diskType , backupVolumeUuid );
9090 diskType = "datadisk" ;
91- try {
92- replaceVolumeWithBackup (restoreVolumePath , bkpPathAndVolUuid .first ());
93- } catch (IOException e ) {
94- throw new CloudRuntimeException (String .format ("Unable to revert backup for volume [%s] due to [%s]." , bkpPathAndVolUuid .second (), e .getMessage ()), e );
91+ if (!replaceVolumeWithBackup (restoreVolumePath , bkpPathAndVolUuid .first ())) {
92+ throw new CloudRuntimeException (String .format ("Unable to restore contents from the backup volume [%s]." , bkpPathAndVolUuid .second ()));
9593 }
9694 }
9795 } finally {
@@ -109,10 +107,8 @@ private void restoreVolumesOfDestroyedVMs(List<String> volumePaths, String vmNam
109107 String volumePath = volumePaths .get (i );
110108 Pair <String , String > bkpPathAndVolUuid = getBackupPath (mountDirectory , volumePath , backupPath , diskType , null );
111109 diskType = "datadisk" ;
112- try {
113- replaceVolumeWithBackup (volumePath , bkpPathAndVolUuid .first ());
114- } catch (IOException e ) {
115- throw new CloudRuntimeException (String .format ("Unable to revert backup for volume [%s] due to [%s]." , bkpPathAndVolUuid .second (), e .getMessage ()), e );
110+ if (!replaceVolumeWithBackup (volumePath , bkpPathAndVolUuid .first ())) {
111+ throw new CloudRuntimeException (String .format ("Unable to restore contents from the backup volume [%s]." , bkpPathAndVolUuid .second ()));
116112 }
117113 }
118114 } finally {
@@ -127,15 +123,13 @@ private void restoreVolume(String backupPath, String backupRepoType, String back
127123 Pair <String , String > bkpPathAndVolUuid ;
128124 try {
129125 bkpPathAndVolUuid = getBackupPath (mountDirectory , volumePath , backupPath , diskType , volumeUUID );
130- try {
131- replaceVolumeWithBackup ( volumePath , bkpPathAndVolUuid .first ( ));
132- if ( VirtualMachine . State . Running . equals ( vmNameAndState . second ())) {
133- if (! attachVolumeToVm (vmNameAndState .first (), volumePath )) {
134- throw new CloudRuntimeException ( String . format ( "Failed to attach volume to VM: %s" , vmNameAndState .first ()));
135- }
126+ if (! replaceVolumeWithBackup ( volumePath , bkpPathAndVolUuid . first ())) {
127+ throw new CloudRuntimeException ( String . format ( "Unable to restore contents from the backup volume [%s]." , bkpPathAndVolUuid .second () ));
128+ }
129+ if (VirtualMachine . State . Running . equals (vmNameAndState .second () )) {
130+ if (! attachVolumeToVm ( vmNameAndState .first (), volumePath )) {
131+ throw new CloudRuntimeException ( String . format ( "Failed to attach volume to VM: %s" , vmNameAndState . first ()));
136132 }
137- } catch (IOException e ) {
138- throw new CloudRuntimeException (String .format ("Unable to revert backup for volume [%s] due to [%s]." , bkpPathAndVolUuid .second (), e .getMessage ()), e );
139133 }
140134 } catch (Exception e ) {
141135 throw new CloudRuntimeException ("Failed to restore volume" , e );
@@ -194,8 +188,9 @@ private Pair<String, String> getBackupPath(String mountDirectory, String volumeP
194188 return new Pair <>(bkpPath , volUuid );
195189 }
196190
197- private void replaceVolumeWithBackup (String volumePath , String backupPath ) throws IOException {
198- Script .runSimpleBashScript (String .format (RSYNC_COMMAND , backupPath , volumePath ));
191+ private boolean replaceVolumeWithBackup (String volumePath , String backupPath ) {
192+ int exitValue = Script .runSimpleBashScriptForExitValue (String .format (RSYNC_COMMAND , backupPath , volumePath ));
193+ return exitValue == 0 ;
199194 }
200195
201196 private boolean attachVolumeToVm (String vmName , String volumePath ) {
0 commit comments