Skip to content

Commit cc782d7

Browse files
vkarasalaVeryEarly
andauthored
[AppServices] RestoreAzureWebAppSnapshot fetch the data from Microsoft.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]>
1 parent 1b8ef91 commit cc782d7

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/Websites/Websites/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixd the source app retrival from Microsoft.Web RP instead of ARM cache for `RestoreAzureWebAppSnapshot`
2122
* Upgraded nuget package to signed package.
2223

2324
## Version 3.2.2

src/Websites/Websites/Cmdlets/BackupRestore/RestoreAzureWebAppSnapshot.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,34 @@ public class RestoreAzureWebAppSnapshot : WebAppOptionalSlotBaseCmdlet
5151
public override void ExecuteCmdlet()
5252
{
5353
base.ExecuteCmdlet();
54-
var sourceApp = ResourcesClient.GetAppResource(InputObject.Name, InputObject.Slot);
54+
var sourceAppLocation = string.Empty;
55+
var sourceAppArmResourceId = string.Empty;
56+
57+
// Try to get the source app location and resource ID from Microsoft.Web RP
58+
try
59+
{
60+
var app = new PSSite(WebsitesClient.GetWebApp(InputObject.ResourceGroupName, InputObject.Name, InputObject.Slot));
61+
sourceAppLocation = app.Location;
62+
sourceAppArmResourceId = app.Id;
63+
WriteDebug($"Fetched the source app location and resource ID from Microsoft.Web RP for {InputObject.Name}, Location = {sourceAppLocation}, Id = {sourceAppArmResourceId}");
64+
}
65+
catch (Exception ex)
66+
{
67+
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");
68+
}
69+
70+
// 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
71+
if (string.IsNullOrEmpty(sourceAppLocation) || string.IsNullOrEmpty(sourceAppArmResourceId))
72+
{
73+
var sourceApp = ResourcesClient.GetAppResource(InputObject.Name, InputObject.Slot);
74+
sourceAppLocation = sourceApp?.Location;
75+
sourceAppArmResourceId = sourceApp?.Id;
76+
}
77+
5578
SnapshotRecoverySource source = new SnapshotRecoverySource()
5679
{
57-
Location = sourceApp?.Location,
58-
Id = sourceApp?.Id
80+
Location = sourceAppLocation,
81+
Id = sourceAppArmResourceId
5982
};
6083
SnapshotRestoreRequest recoveryReq = new SnapshotRestoreRequest()
6184
{

0 commit comments

Comments
 (0)