diff --git a/src/Websites/Websites/ChangeLog.md b/src/Websites/Websites/ChangeLog.md index a0583e3bae03..59fc3a53427d 100644 --- a/src/Websites/Websites/ChangeLog.md +++ b/src/Websites/Websites/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Fixd the source app retrival from Microsoft.Web RP instead of ARM cache for `RestoreAzureWebAppSnapshot` * Upgraded nuget package to signed package. ## Version 3.2.2 diff --git a/src/Websites/Websites/Cmdlets/BackupRestore/RestoreAzureWebAppSnapshot.cs b/src/Websites/Websites/Cmdlets/BackupRestore/RestoreAzureWebAppSnapshot.cs index 21167ee5942c..06131067d40f 100644 --- a/src/Websites/Websites/Cmdlets/BackupRestore/RestoreAzureWebAppSnapshot.cs +++ b/src/Websites/Websites/Cmdlets/BackupRestore/RestoreAzureWebAppSnapshot.cs @@ -51,11 +51,34 @@ public class RestoreAzureWebAppSnapshot : WebAppOptionalSlotBaseCmdlet public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - var sourceApp = ResourcesClient.GetAppResource(InputObject.Name, InputObject.Slot); + var sourceAppLocation = string.Empty; + var sourceAppArmResourceId = string.Empty; + + // Try to get the source app location and resource ID from Microsoft.Web RP + try + { + var app = new PSSite(WebsitesClient.GetWebApp(InputObject.ResourceGroupName, InputObject.Name, InputObject.Slot)); + sourceAppLocation = app.Location; + sourceAppArmResourceId = app.Id; + WriteDebug($"Fetched the source app location and resource ID from Microsoft.Web RP for {InputObject.Name}, Location = {sourceAppLocation}, Id = {sourceAppArmResourceId}"); + } + catch (Exception ex) + { + WriteDebug($"Unable to fetch the source app location and resource ID from Microsoft.Web RP. {ex.Message}, An attempt will be made to retrieve the same from ARM cache"); + } + + // Fall back code to fetch the source app location and resource ID from ARM cache, Useful with disaster recovery scenaior's when Microsoft.Web RP is not accessible + if (string.IsNullOrEmpty(sourceAppLocation) || string.IsNullOrEmpty(sourceAppArmResourceId)) + { + var sourceApp = ResourcesClient.GetAppResource(InputObject.Name, InputObject.Slot); + sourceAppLocation = sourceApp?.Location; + sourceAppArmResourceId = sourceApp?.Id; + } + SnapshotRecoverySource source = new SnapshotRecoverySource() { - Location = sourceApp?.Location, - Id = sourceApp?.Id + Location = sourceAppLocation, + Id = sourceAppArmResourceId }; SnapshotRestoreRequest recoveryReq = new SnapshotRestoreRequest() {