Skip to content

Commit 610b499

Browse files
author
Nicholas King
committed
Reworked snapshots cmdlets based on feedback
Recorded snapshots tests again Regenerated Restore-AzureRmWebAppSnapshot and filled in help examples. Refactored RestoreAzureWebAppSnapshot cmdlet. ResourceGroup and Name parameters specify target app. Rewrote RestoreAzureRmWebAppSnapshot cmdlet help.
1 parent 795da06 commit 610b499

File tree

12 files changed

+1543
-18535
lines changed

12 files changed

+1543
-18535
lines changed

src/ResourceManager/Websites/AzureRM.Websites.Netcore.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ CmdletsToExport = 'Get-AzureRmAppServicePlan', 'Set-AzureRmAppServicePlan',
9393
'New-AzureRmWebAppBackup', 'Remove-AzureRmWebApp',
9494
'New-AzureRmWebApp', 'Remove-AzureRmWebAppBackup',
9595
'Reset-AzureRmWebAppPublishingProfile', 'Restart-AzureRmWebApp',
96-
'Set-AzureRmWebApp', 'Start-AzureRmWebApp', 'Stop-AzureRmWebApp'
96+
'Set-AzureRmWebApp', 'Start-AzureRmWebApp', 'Stop-AzureRmWebApp',
97+
'Get-AzureRmWebAppSnapshots', 'Restore-AzureRmWebAppSnapshot'
9798

9899
# Variables to export from this module
99100
# VariablesToExport = @()

src/ResourceManager/Websites/AzureRM.Websites.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ CmdletsToExport = 'Get-AzureRmAppServicePlan', 'Set-AzureRmAppServicePlan',
9494
'New-AzureRmWebAppBackup', 'Remove-AzureRmWebApp',
9595
'New-AzureRmWebApp', 'Remove-AzureRmWebAppBackup',
9696
'Reset-AzureRmWebAppPublishingProfile', 'Restart-AzureRmWebApp',
97-
'Set-AzureRmWebApp', 'Start-AzureRmWebApp', 'Stop-AzureRmWebApp'
97+
'Set-AzureRmWebApp', 'Start-AzureRmWebApp', 'Stop-AzureRmWebApp',
98+
'Get-AzureRmWebAppSnapshot', 'Restore-AzureRmWebAppSnapshot'
9899

99100
# Variables to export from this module
100101
# VariablesToExport = @()

src/ResourceManager/Websites/Commands.Websites.Test/Commands.Websites.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestGetWebAppBackupList.json">
215215
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
216216
</None>
217-
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestGetWebAppSnapshots.json">
217+
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestGetWebAppSnapshot.json">
218218
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
219219
</None>
220220
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestRestoreWebAppSnapshot.json">

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,19 @@ public void TestEditAndGetWebAppBackupConfigurationPiping()
6868
{
6969
WebsitesController.NewInstance.RunPsTest("Test-EditAndGetWebAppBackupConfigurationPiping");
7070
}
71+
72+
[Fact]
73+
[Trait(Category.AcceptanceType, Category.CheckIn)]
74+
public void TestGetWebAppSnapshot()
75+
{
76+
WebsitesController.NewInstance.RunPsTest("Test-GetWebAppSnapshot");
77+
}
78+
79+
[Fact]
80+
[Trait(Category.AcceptanceType, Category.CheckIn)]
81+
public void TestRestoreWebAppSnapshot()
82+
{
83+
WebsitesController.NewInstance.RunPsTest("Test-RestoreWebAppSnapshot");
84+
}
7185
}
7286
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ function Test-EditAndGetWebAppBackupConfigurationPiping
328328
}
329329
}
330330

331-
function Test-GetWebAppSnapshots
331+
function Test-GetWebAppSnapshot
332332
{
333333
# Test named parameters
334334
$snapshots = Get-AzureRmWebAppSnapshot -ResourceGroupName $snapshotRgName -Name $snapshotAppName
@@ -364,17 +364,13 @@ function Test-RestoreWebAppSnapshot
364364
{
365365
# Test overwrite
366366
$snapshot = (Get-AzureRmWebAppSnapshot $snapshotRgName $snapshotAppName)[0]
367-
Restore-AzureRmWebAppSnapshot -ResourceGroupName $snapshotRgName -Name $snapshotAppName -SnapshotTime $snapshot.SnapshotTime -Force -RecoverConfiguration
367+
Restore-AzureRmWebAppSnapshot -ResourceGroupName $snapshotRgName -Name $snapshotAppName -InputObject $snapshot -Force -RecoverConfiguration
368368

369369
# Test restore to target slot
370-
$target = Get-AzureRmWebAppSlot -ResourceGroupName $snapshotRgName -Name $snapshotAppName -Slot $snapshotAppSlot
371-
Restore-AzureRmWebAppSnapshot -ResourceGroupName $snapshotRgName -Name $snapshotAppName -SnapshotTime $snapshot.SnapshotTime -RecoverConfiguration -TargetApp $target
370+
Restore-AzureRmWebAppSnapshot $snapshotRgName $snapshotAppName $snapshotAppSlot $snapshot -RecoverConfiguration -Force
372371

373-
# Test piping
374-
$snapshot | Restore-AzureRmWebAppSnapshot -Force
375-
376-
# Test background job
377-
$snapshot | Restore-AzureRmWebAppSnapshot -Force -AsJob
372+
# Test piping and background job
373+
$job = $snapshot | Restore-AzureRmWebAppSnapshot -Force -AsJob
378374
$job | Wait-Job
379375
}
380376

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

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

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

Lines changed: 0 additions & 575 deletions
This file was deleted.

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

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

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

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.WebApps.Models;
1516
using Microsoft.Azure.Commands.WebApps.Utilities;
1617
using Microsoft.Azure.Management.WebSites.Models;
1718
using System;
@@ -29,22 +30,15 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.BackupRestore
2930
[Cmdlet(VerbsData.Restore, "AzureRmWebAppSnapshot", SupportsShouldProcess = true)]
3031
public class RestoreAzureWebAppSnapshot : WebAppOptionalSlotBaseCmdlet
3132
{
32-
protected const string SnapshotParameterSetName = "FromWebAppSnapshot";
33-
34-
[Parameter(ParameterSetName = SnapshotParameterSetName, Position = 0, Mandatory = true,
33+
[Parameter(ParameterSetName = ParameterSet1Name, Position = 3, Mandatory = true,
3534
HelpMessage = "The Azure Web App snapshot.", ValueFromPipeline = true)]
36-
public AzureWebAppSnapshot WebAppSnapshot;
37-
38-
[Parameter(Position = 3, Mandatory = true, HelpMessage = "The timestamp of the snapshot.", ValueFromPipelineByPropertyName = true)]
39-
[ValidateNotNullOrEmpty]
40-
public DateTime SnapshotTime;
35+
[Parameter(ParameterSetName = ParameterSet2Name, Position = 1, Mandatory = true,
36+
HelpMessage = "The Azure Web App snapshot.", ValueFromPipeline = true)]
37+
public AzureWebAppSnapshot InputObject;
4138

4239
[Parameter(Mandatory = false, HelpMessage = "Recover the web app's configuration in addition to files.", ValueFromPipelineByPropertyName = true)]
4340
public SwitchParameter RecoverConfiguration { get; set; }
4441

45-
[Parameter(Mandatory = false, HelpMessage = "The app that the snapshot contents will be restored to. Must be a slot of the original app. If unspecified, the original app is overwritten.", ValueFromPipelineByPropertyName = true)]
46-
public Site TargetApp { get; set; }
47-
4842
[Parameter(Mandatory = false, HelpMessage = "Allows the original web app to be overwritten without displaying a warning.", ValueFromPipelineByPropertyName = true)]
4943
public SwitchParameter Force { get; set; }
5044

@@ -54,42 +48,23 @@ public class RestoreAzureWebAppSnapshot : WebAppOptionalSlotBaseCmdlet
5448
public override void ExecuteCmdlet()
5549
{
5650
base.ExecuteCmdlet();
57-
switch (ParameterSetName)
58-
{
59-
case SnapshotParameterSetName:
60-
ResourceGroupName = WebAppSnapshot.ResourceGroupName;
61-
Name = WebAppSnapshot.Name;
62-
Slot = WebAppSnapshot.Slot;
63-
SnapshotTime = WebAppSnapshot.SnapshotTime;
64-
break;
65-
}
66-
SnapshotRecoveryTarget target = null;
67-
if (this.TargetApp != null)
51+
Site targetApp = WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot);
52+
SnapshotRecoveryTarget target = new SnapshotRecoveryTarget()
6853
{
69-
string webAppName, slotName;
70-
CmdletHelpers.TryParseAppAndSlotNames(Name, out webAppName, out slotName);
71-
if (!string.Equals(this.TargetApp.ResourceGroup, this.ResourceGroupName, StringComparison.InvariantCultureIgnoreCase) ||
72-
!string.Equals(webAppName, this.Name, StringComparison.InvariantCultureIgnoreCase))
73-
{
74-
throw new PSArgumentException("Target app must be a slot of the source web app");
75-
}
76-
target = new SnapshotRecoveryTarget()
77-
{
78-
Location = TargetApp.Location,
79-
Id = TargetApp.Id
80-
};
81-
}
54+
Location = targetApp.Location,
55+
Id = targetApp.Id
56+
};
8257
SnapshotRecoveryRequest recoveryReq = new SnapshotRecoveryRequest()
8358
{
8459
Overwrite = true,
85-
SnapshotTime = this.SnapshotTime.ToString("o"),
60+
SnapshotTime = this.InputObject.SnapshotTime.ToString("o"),
8661
RecoverConfiguration = this.RecoverConfiguration,
8762
IgnoreConflictingHostNames = true,
8863
RecoveryTarget = target
8964
};
90-
Action recoverAction = () => WebsitesClient.RecoverSite(ResourceGroupName, Name, Slot, recoveryReq);
91-
ConfirmAction(TargetApp != null || this.Force.IsPresent, "Original web app contents will be overwritten with the contents of the snapshot.",
92-
"The snapshot has been restored.", Name, recoverAction);
65+
Action recoverAction = () => WebsitesClient.RecoverSite(InputObject.ResourceGroupName, InputObject.Name, InputObject.Slot, recoveryReq);
66+
ConfirmAction(this.Force.IsPresent, "Web app contents will be overwritten with the contents of the snapshot.",
67+
"The snapshot has been restored.", InputObject.Name, recoverAction);
9368
}
9469
}
9570
}

src/ResourceManager/Websites/Commands.Websites/Commands.Websites.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@
5858
<Compile Include="Cmdlets\BackupRestore\AzureWebAppBackupConfiguration.cs" />
5959
<Compile Include="Cmdlets\BackupRestore\AzureWebAppSnapshot.cs" />
6060
<Compile Include="Cmdlets\BackupRestore\BackupRestoreUtils.cs" />
61+
<Compile Include="Cmdlets\BackupRestore\GetAzureWebAppSnapshot.cs" />
6162
<Compile Include="Cmdlets\BackupRestore\NewAzureRmWebAppDatabaseBackupSetting.cs" />
6263
<Compile Include="Cmdlets\BackupRestore\RestoreAzureWebAppBackup.cs" />
64+
<Compile Include="Cmdlets\BackupRestore\RestoreAzureWebAppSnapshot.cs" />
6365
<Compile Include="Cmdlets\Certificates\GetAzureWebAppCertificate.cs" />
6466
<Compile Include="Cmdlets\Certificates\GetAzureWebAppSSLBinding.cs" />
6567
<Compile Include="Cmdlets\Certificates\NewAzureWebAppSSLBinding.cs" />
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
external help file: Microsoft.Azure.Commands.Websites.dll-Help.xml
3+
Module Name: AzureRM.WebSites
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Get-AzureRmWebAppSnapshot
9+
10+
## SYNOPSIS
11+
Gets the snapshots available for a web app.
12+
13+
## SYNTAX
14+
15+
### FromResourceName
16+
```
17+
Get-AzureRmWebAppSnapshot [-ResourceGroupName] <String> [-Name] <String> [[-Slot] <String>]
18+
[-DefaultProfile <IAzureContextContainer>]
19+
```
20+
21+
### FromWebApp
22+
```
23+
Get-AzureRmWebAppSnapshot [-WebApp] <Site> [-DefaultProfile <IAzureContextContainer>]
24+
```
25+
26+
## DESCRIPTION
27+
The **Get-AzureRmWebAppSnapshot** cmdlet returns all snapshots for a web app. Snapshots are automatic backups of a web app's files and settings. A snapshot can be restored with the **Restore-AzureRmWebAppSnapshot** cmdlet.
28+
29+
## EXAMPLES
30+
31+
### Example 1
32+
```
33+
PS C:\> Get-AzureRmWebAppSnapshot -ResourceGroupName "Default-Web-WestUS" -Name "ContosoApp" -Slot "Staging"
34+
```
35+
36+
Get the snapshots for a web app named "ConstosoApp" with a slot named "Staging" in the "Default-Web-WestUS" resource group
37+
38+
## PARAMETERS
39+
40+
### -DefaultProfile
41+
The credentials, account, tenant, and subscription used for communication with Azure.
42+
43+
```yaml
44+
Type: IAzureContextContainer
45+
Parameter Sets: (All)
46+
Aliases: AzureRmContext, AzureCredential
47+
48+
Required: False
49+
Position: Named
50+
Default value: None
51+
Accept pipeline input: False
52+
Accept wildcard characters: False
53+
```
54+
55+
### -Name
56+
The name of the web app.
57+
58+
```yaml
59+
Type: String
60+
Parameter Sets: FromResourceName
61+
Aliases:
62+
63+
Required: True
64+
Position: 1
65+
Default value: None
66+
Accept pipeline input: True (ByPropertyName)
67+
Accept wildcard characters: False
68+
```
69+
70+
### -ResourceGroupName
71+
The name of the resource group.
72+
73+
```yaml
74+
Type: String
75+
Parameter Sets: FromResourceName
76+
Aliases:
77+
78+
Required: True
79+
Position: 0
80+
Default value: None
81+
Accept pipeline input: True (ByPropertyName)
82+
Accept wildcard characters: False
83+
```
84+
85+
### -Slot
86+
The name of the web app slot.
87+
88+
```yaml
89+
Type: String
90+
Parameter Sets: FromResourceName
91+
Aliases:
92+
93+
Required: False
94+
Position: 2
95+
Default value: None
96+
Accept pipeline input: True (ByPropertyName)
97+
Accept wildcard characters: False
98+
```
99+
100+
### -WebApp
101+
The web app object
102+
103+
```yaml
104+
Type: Site
105+
Parameter Sets: FromWebApp
106+
Aliases:
107+
108+
Required: True
109+
Position: 0
110+
Default value: None
111+
Accept pipeline input: True (ByValue)
112+
Accept wildcard characters: False
113+
```
114+
115+
## INPUTS
116+
117+
### System.String
118+
Microsoft.Azure.Management.WebSites.Models.Site
119+
120+
121+
## OUTPUTS
122+
123+
### Microsoft.Azure.Commands.WebApps.Cmdlets.BackupRestore.AzureWebAppSnapshot
124+
125+
126+
## NOTES
127+
128+
## RELATED LINKS
129+

0 commit comments

Comments
 (0)