Skip to content

Commit a2939fa

Browse files
raohri3VeryEarly
andauthored
Add Documentation for restore from Deleted app (Azure#12057)
* adding SourceWebApp.Location details * Update ChangeLog.md * Add Details in documentation * Correcting powershell * Remove app created to restore in case of Failure * Update ChangeLog.md Co-authored-by: Yabo Hu <[email protected]>
1 parent 12c76b9 commit a2939fa

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
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+
* Added safeguard to delete created webapp if restore failed in `Restore-AzDeletedWebApp`
2122
* Added "SourceWebApp.Location" for `New-AzWebApp` and `New-AzWebAppSlot`
2223

2324
## Version 1.9.0

src/Websites/Websites/Cmdlets/BackupRestore/RestoreAzureDeletedWebApp.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,26 @@ public override void ExecuteCmdlet()
105105
{
106106
throw new Exception("Target App Service Plan " + TargetAppServicePlanName + " not found in target Resource Group " + TargetResourceGroupName);
107107
}
108-
Action createRestoreAction = () =>
108+
try
109109
{
110-
WebsitesClient.CreateWebApp(TargetResourceGroupName, TargetName, TargetSlot, plan.Location, TargetAppServicePlanName,
111-
null, string.Empty, string.Empty);
112-
restoreAction();
113-
};
114-
string confirmMsg = string.Format("This web app will be created. App Name: {0}, Resource Group: {1}", TargetName, TargetResourceGroupName);
115-
if (!string.IsNullOrEmpty(TargetSlot))
110+
Action createRestoreAction = () =>
111+
{
112+
WebsitesClient.CreateWebApp(TargetResourceGroupName, TargetName, TargetSlot, plan.Location, TargetAppServicePlanName,
113+
null, string.Empty, string.Empty);
114+
restoreAction();
115+
};
116+
string confirmMsg = string.Format("This web app will be created. App Name: {0}, Resource Group: {1}", TargetName, TargetResourceGroupName);
117+
if (!string.IsNullOrEmpty(TargetSlot))
118+
{
119+
confirmMsg += ", Slot: " + TargetSlot;
120+
}
121+
ConfirmAction(this.Force.IsPresent, confirmMsg, "The deleted app has been restored.", TargetName, createRestoreAction);
122+
}
123+
catch (Exception e)
116124
{
117-
confirmMsg += ", Slot: " + TargetSlot;
125+
WebsitesClient.RemoveWebApp(TargetResourceGroupName, TargetName, TargetSlot, true, true, false);
126+
throw e;
118127
}
119-
ConfirmAction(this.Force.IsPresent, confirmMsg, "The deleted app has been restored.", TargetName, createRestoreAction);
120128
}
121129

122130
PSSite restoredApp = new PSSite(WebsitesClient.GetWebApp(TargetResourceGroupName, TargetName, TargetSlot));

src/Websites/Websites/help/Restore-AzDeletedWebApp.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ PS C:\> Restore-AzDeletedWebApp -ResourceGroupName Default-Web-WestUS -Name Cont
4747

4848
Restores the Staging slot of a deleted app named ContosoApp belonging to the resource group Default-Web-WestUS. The web app named ContosoRestore belonging to the resource group Default-Web-EastUS will be overwritten. The deleted web app settings will not be restored.
4949

50+
###Example 3
51+
```powershell
52+
PS C:\> $deletedSite = Get-AzDeletedWebApp -ResourceGroupName Default-Web-WestUS -Name ContosoApp
53+
PS C:\> Restore-AzDeletedWebApp -TargetResourceGroupName Default-Web-EastUS -TargetName ContosoRestore -TargetAppServicePlanName ContosoPlan -InputObject $deletedSite[0]
54+
```
55+
56+
In case there are 2 deleted apps with same name(ContosoApp), then we get details of both the sites and restore the app named ContosoRestore with the app of our choice by calling restore with InputObject(Deletedsite) details
57+
5058
## PARAMETERS
5159

5260
### -AsJob

0 commit comments

Comments
 (0)