Skip to content

Commit f949907

Browse files
authored
Merge pull request #9177 from Nking92/master
Az.Websites - Improvements for disaster recovery scenario cmdlets
2 parents 58385a7 + 11439b1 commit f949907

File tree

13 files changed

+971
-1718
lines changed

13 files changed

+971
-1718
lines changed

src/Websites/Websites.Test/ScenarioTests/WebAppBackupRestoreTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,21 @@ public void TestRestoreWebAppSnapshot()
116116
WebsitesController.NewInstance.RunPsTest(_logger, "Test-RestoreWebAppSnapshot");
117117
}
118118

119-
[Fact(Skip="Get-AzDeletedWebApp returning null in recorded tests #9191")]
119+
[Fact]
120120
[Trait(Category.AcceptanceType, Category.CheckIn)]
121121
public void TestGetDeletedWebApp()
122122
{
123123
WebsitesController.NewInstance.RunPsTest(_logger, "Test-GetDeletedWebApp");
124124
}
125125

126-
[Fact(Skip="Get-AzDeletedWebApp returning null in recorded tests #9191")]
126+
[Fact]
127127
[Trait(Category.AcceptanceType, Category.CheckIn)]
128128
public void TestRestoreDeletedWebAppToExisting()
129129
{
130130
WebsitesController.NewInstance.RunPsTest(_logger, "Test-RestoreDeletedWebAppToExisting");
131131
}
132132

133-
[Fact(Skip="Get-AzDeletedWebApp returning null in recorded tests #9191")]
133+
[Fact]
134134
[Trait(Category.AcceptanceType, Category.CheckIn)]
135135
public void TestRestoreDeletedWebAppToNew()
136136
{

src/Websites/Websites.Test/ScenarioTests/WebAppBackupRestoreTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ $snapshotAppSlot = 'staging'
2121
# Restoring a deleted web app requires an app to have a snapshot available.
2222
# Deploy a web app and wait at least an hour for a snapshot.
2323
# Update these global variables to re-record Test-RestoreDeletedWebApp.
24-
$undeleteRgName = 'nickingssltests'
25-
$undeleteAppName = 'nkundeletetest'
24+
$undeleteRgName = 'web2'
25+
$undeleteAppName = 'undeletesrc'
2626
$undeleteSlot = 'testslot'
2727

2828
# !!! Storage keys and SAS URIs will be stored in the backup test recordings !!!
@@ -343,7 +343,7 @@ function Test-EditAndGetWebAppBackupConfigurationPiping
343343
function Test-GetWebAppSnapshot
344344
{
345345
# Test named parameters
346-
$snapshots = Get-AzWebAppSnapshot -ResourceGroupName $snapshotRgName -Name $snapshotAppName
346+
$snapshots = Get-AzWebAppSnapshot -ResourceGroupName $snapshotRgName -Name $snapshotAppName -UseDisasterRecovery
347347
Assert-True { $snapshots.Length -gt 0 }
348348
Assert-NotNull $snapshots[0]
349349
Assert-NotNull $snapshots[0].SnapshotTime

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests/TestGetWebAppSnapshot.json

Lines changed: 66 additions & 66 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests/TestRestoreDeletedWebAppToExisting.json

Lines changed: 440 additions & 440 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests/TestRestoreDeletedWebAppToNew.json

Lines changed: 219 additions & 219 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests/TestRestoreWebAppSnapshot.json

Lines changed: 177 additions & 975 deletions
Large diffs are not rendered by default.

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+
* Adds -UseDisasterRecovery switch parameter to Get-AzWebAppSnapshot
2122

2223
## Version 1.2.2
2324
* fixes the issue where using Set-AzWebApp and Set-AzWebAppSlot with -WebApp property was removing the tags

src/Websites/Websites/Cmdlets/BackupRestore/GetAzureDeletedWebApp.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public override void ExecuteCmdlet()
6060
}
6161
);
6262

63-
// Filter out deleted sites older than 30 days.
64-
// They can't be restored and eventually will not be returned by the GetDeletedSites API.
65-
deletedSites = deletedSites.Where(ds => ds.DeletionTime >= DateTime.UtcNow.AddDays(-30)).OrderBy(ds => ds.DeletionTime);
66-
6763
if (!string.IsNullOrEmpty(ResourceGroupName))
6864
{
6965

src/Websites/Websites/Cmdlets/BackupRestore/GetAzureWebAppSnapshot.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.BackupRestore
2121
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "WebAppSnapshot"), OutputType(typeof(AzureWebAppSnapshot))]
2222
public class GetAzureWebAppSnapshot : WebAppOptionalSlotBaseCmdlet
2323
{
24+
25+
[Parameter(Mandatory = false, HelpMessage = "Read the snapshots from a secondary scale unit.")]
26+
public SwitchParameter UseDisasterRecovery { get; set; }
27+
2428
public override void ExecuteCmdlet()
2529
{
2630
base.ExecuteCmdlet();
27-
var list = WebsitesClient.GetSiteSnapshots(ResourceGroupName, Name, Slot).Select(s => {
31+
var list = WebsitesClient.GetSiteSnapshots(ResourceGroupName, Name, Slot, UseDisasterRecovery.IsPresent).Select(s => {
2832
return new AzureWebAppSnapshot()
2933
{
3034
ResourceGroupName = this.ResourceGroupName,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class RestoreAzureWebAppSnapshot : WebAppOptionalSlotBaseCmdlet
5151
public override void ExecuteCmdlet()
5252
{
5353
base.ExecuteCmdlet();
54-
var sourceApp = new PSSite(WebsitesClient.GetWebApp(InputObject.ResourceGroupName, InputObject.Name, InputObject.Slot));
54+
var sourceApp = ResourcesClient.GetAppResource(InputObject.Name, InputObject.Slot);
5555
SnapshotRecoverySource source = new SnapshotRecoverySource()
5656
{
5757
Location = sourceApp.Location,

src/Websites/Websites/Models.WebApp/ResourceClient.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.Azure.Management.Internal.Resources;
2121
using Microsoft.Azure.Management.Internal.Resources.Models;
2222
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
23+
using Microsoft.Rest.Azure.OData;
2324
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2425
using Newtonsoft.Json;
2526
using System;
@@ -114,6 +115,23 @@ private void WriteError(string error)
114115
}
115116
}
116117

118+
/// <summary>
119+
/// Gets a web app resource from the ARM cache.
120+
/// </summary>
121+
public GenericResource GetAppResource(string name, string slot = null)
122+
{
123+
ODataQuery<GenericResourceFilter> query;
124+
if (string.IsNullOrEmpty(slot) || string.Equals(slot, "production", StringComparison.InvariantCultureIgnoreCase))
125+
{
126+
query = new ODataQuery<GenericResourceFilter>($"resourceType eq 'Microsoft.Web/sites' and name eq '{name}'");
127+
}
128+
else
129+
{
130+
query = new ODataQuery<GenericResourceFilter>($"resourceType eq 'Microsoft.Web/sites/slots' and name eq '{name}/{slot}'");
131+
}
132+
return ResourceManagementClient.Resources.List(query).FirstOrDefault();
133+
}
134+
117135
public DeploymentExtended ProvisionDeploymentStatus(string resourceGroup, string deploymentName, Deployment deployment)
118136
{
119137
operations = new List<DeploymentOperation>();

src/Websites/Websites/Utilities/WebsitesClient.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,33 @@ public void RestoreSite(string resourceGroupName, string webSiteName, string slo
735735
}
736736
}
737737

738-
public IList<Snapshot> GetSiteSnapshots(string resourceGroupName, string webSiteName, string slotName)
738+
public IList<Snapshot> GetSiteSnapshots(string resourceGroupName, string webSiteName, string slotName, bool useDrSecondary)
739739
{
740740
string qualifiedSiteName;
741741
bool useSlot = CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName);
742742
if (useSlot)
743743
{
744-
return WrappedWebsitesClient.WebApps.ListSnapshotsSlot(resourceGroupName, webSiteName, slotName).ToList();
744+
if (useDrSecondary)
745+
{
746+
return WrappedWebsitesClient.WebApps.ListSnapshotsFromDRSecondarySlot(resourceGroupName, webSiteName, slotName).ToList();
747+
748+
}
749+
else
750+
{
751+
return WrappedWebsitesClient.WebApps.ListSnapshotsSlot(resourceGroupName, webSiteName, slotName).ToList();
752+
}
745753
}
746754
else
747755
{
748-
return WrappedWebsitesClient.WebApps.ListSnapshots(resourceGroupName, webSiteName).ToList();
756+
if (useDrSecondary)
757+
{
758+
return WrappedWebsitesClient.WebApps.ListSnapshotsFromDRSecondary(resourceGroupName, webSiteName).ToList();
759+
760+
}
761+
else
762+
{
763+
return WrappedWebsitesClient.WebApps.ListSnapshots(resourceGroupName, webSiteName).ToList();
764+
}
749765
}
750766
}
751767

src/Websites/Websites/help/Get-AzWebAppSnapshot.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
external help file: Microsoft.Azure.PowerShell.Cmdlets.Websites.dll-Help.xml
33
Module Name: Az.Websites
44
online version: https://docs.microsoft.com/en-us/powershell/module/az.websites/get-azwebappsnapshot
@@ -14,13 +14,14 @@ Gets the snapshots available for a web app.
1414

1515
### FromResourceName
1616
```
17-
Get-AzWebAppSnapshot [-ResourceGroupName] <String> [-Name] <String> [[-Slot] <String>]
17+
Get-AzWebAppSnapshot [-UseDisasterRecovery] [-ResourceGroupName] <String> [-Name] <String> [[-Slot] <String>]
1818
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1919
```
2020

2121
### FromWebApp
2222
```
23-
Get-AzWebAppSnapshot [-WebApp] <PSSite> [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
23+
Get-AzWebAppSnapshot [-UseDisasterRecovery] [-WebApp] <PSSite> [-DefaultProfile <IAzureContextContainer>]
24+
[<CommonParameters>]
2425
```
2526

2627
## DESCRIPTION
@@ -97,6 +98,21 @@ Accept pipeline input: True (ByPropertyName)
9798
Accept wildcard characters: False
9899
```
99100
101+
### -UseDisasterRecovery
102+
Read the snapshots from a secondary scale unit.
103+
104+
```yaml
105+
Type: System.Management.Automation.SwitchParameter
106+
Parameter Sets: (All)
107+
Aliases:
108+
109+
Required: False
110+
Position: Named
111+
Default value: None
112+
Accept pipeline input: False
113+
Accept wildcard characters: False
114+
```
115+
100116
### -WebApp
101117
The web app object
102118

0 commit comments

Comments
 (0)