Skip to content

Commit

Permalink
[AppServices] RestoreAzureWebAppSnapshot fetch the data from Microsof…
Browse files Browse the repository at this point in the history
…t.Web RP similar to other commands (#26685)

* [AppServices] RestoreAzureWebAppSnapshot fetch the data from Microsoft.Web RP similar to other commands

* Add warning message

* Add change log and fix an issue

* Fix typo in ChangeLog.md file

---------

Co-authored-by: Yabo Hu <[email protected]>
  • Loading branch information
vkarasala and VeryEarly authored Jan 7, 2025
1 parent 1b8ef91 commit cc782d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Websites/Websites/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit cc782d7

Please sign in to comment.