Skip to content

Commit 7c84cba

Browse files
committed
Updated docs and fixed comments
1 parent caf31a9 commit 7c84cba

File tree

11 files changed

+185
-78
lines changed

11 files changed

+185
-78
lines changed

src/Sql/Sql/ChangeLog.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21-
* Updated `New-AzSqlInstance` to support retention
22-
- Added `EnableSoftDeleteRetention` parameter to `New-AzSqlInstance` to enable the creation of instances with retention period enabled
23-
- Added `SoftDeleteRetentionInDays` parameter to `New-AzSqlInstance` to enable the creation of instances with custom retention period
24-
* Updated `Set-AzSqlInstance` to support retention
25-
- Added `EnableSoftDeleteRetention` parameter to `Set-AzSqlInstance` to enable/disable retention period on existing instances
26-
- Added `SoftDeleteRetentionInDays` parameter to `Set-AzSqlInstance` to enable the update of retention period on existing instances
27-
* Added `Restore-AzSqlServer` cmdlet to restore a deleted Azure Sql servers within the retention period
21+
* Updated `New-AzSqlServer` to support soft-delete retention
22+
- Added `EnableSoftDeleteRetention` parameter to `New-AzSqlServer` to enable creation of a server with soft-delete retention
23+
- Added `SoftDeleteRetentionDays` parameter to `New-AzSqlServer` to set the soft-delete retention period (in days)
24+
* Updated `Set-AzSqlServer` to support soft-delete retention
25+
- Added `EnableSoftDeleteRetention` parameter to `Set-AzSqlServer` to enable or disable soft-delete retention on an existing server
26+
- Added `SoftDeleteRetentionDays` parameter to `Set-AzSqlServer` to update the soft-delete retention period (in days) on an existing server
27+
* Added `Restore-AzSqlServer` cmdlet to restore a deleted Azure SQL server within the retention period
2828

2929
## Version 6.1.0
3030
* Fixed `New-AzSqlDatabaseExport` and `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any mandatory password

src/Sql/Sql/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Sql/Sql/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@
670670
<data name="MissingSQLAdministratorCredentials" xml:space="preserve">
671671
<value>SQL Administrator Credentials are only optional when Azure Active Directory Only Authentication is enabled via -EnableActiveDirectoryOnlyAuthentication.</value>
672672
</data>
673+
<data name="MissingEnableSoftDeleteRetention" xml:space="preserve">
674+
<value>EnableSoftDeleteRetention must be provided when SoftDeleteRetentionDays is set to a value greater than 0.</value>
675+
</data>
673676
<data name="RemoveAzureSqlServerOutboundFirewallRuleDescription" xml:space="preserve">
674677
<value>Permanently removing allowed FQDN '{0}' from the list of Outbound Firewall Rules (Allowed FQDNs) for Azure Sql Database Server '{1}'.</value>
675678
</data>

src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ public override void ExecuteCmdlet()
194194
throw new PSArgumentException(Properties.Resources.MissingSQLAdministratorCredentials, "SqlAdministratorCredentials");
195195
}
196196

197+
// SoftDeleteRetentionDays depends on EnableSoftDeleteRetention; if days are provided but soft-delete is not enabled, fail early.
198+
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays > 0 && !this.EnableSoftDeleteRetention)
199+
{
200+
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDeleteRetention, "EnableSoftDeleteRetention");
201+
}
202+
197203
base.ExecuteCmdlet();
198204
}
199205

@@ -260,7 +266,7 @@ public override void ExecuteCmdlet()
260266
Login = this.ExternalAdminName,
261267
Sid = this.ExternalAdminSID
262268
},
263-
RetentionDays = (this.EnableSoftDeleteRetention && !this.SoftDeleteRetentionDays.HasValue) ? 7 : this.SoftDeleteRetentionDays
269+
SoftDeleteRetentionDays = (this.EnableSoftDeleteRetention && !this.SoftDeleteRetentionDays.HasValue) ? 7 : this.SoftDeleteRetentionDays
264270
});
265271
return newEntity;
266272
}

src/Sql/Sql/Server/Cmdlet/RestoreAzureSqlServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public override void ExecuteCmdlet()
9999
var deletedServer = ModelAdapter.GetDeletedServer(this.ResourceGroupName, this.ServerName);
100100
if (deletedServer == null)
101101
{
102-
throw new PSArgumentException(
103-
string.Format("No deleted server named '{0}' found in resource group '{1}' that can be restored.",
104-
this.ServerName, this.ResourceGroupName),
105-
"ServerName");
102+
throw new PSArgumentException(
103+
string.Format("No deleted server named '{0}' found in resource group '{1}' that can be restored.",
104+
this.ServerName, this.ResourceGroupName),
105+
"ServerName");
106106
}
107107

108108
// Deleted server exists and can be restored

src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,27 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
139139
[Parameter(Mandatory = false,
140140
HelpMessage = "Value for soft-delete retention days for the server such that the server can be restored for the specified number of days after dropping. Only valid values are from 0 to 35. If set to 0, soft-delete retention is disabled.")]
141141
[PSArgumentCompleter("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35")]
142-
public int? RetentionDays { get; set; }
142+
public int? SoftDeleteRetentionDays { get; set; }
143143

144144
/// <summary>
145145
/// Defines whether it is ok to skip the requesting of rule removal confirmation
146146
/// </summary>
147147
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
148148
public SwitchParameter Force { get; set; }
149149

150+
/// <summary>
151+
/// Overriding to add warning message
152+
/// </summary>
153+
public override void ExecuteCmdlet()
154+
{
155+
// SoftDeleteRetentionDays depends on EnableSoftDeleteRetention; if days are provided but soft-delete is not enabled, fail early.
156+
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays > 0 && !this.EnableSoftDeleteRetention)
157+
{
158+
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDeleteRetention, "EnableSoftDeleteRetention");
159+
}
160+
161+
base.ExecuteCmdlet();
162+
}
150163
/// <summary>
151164
/// Get the server to update
152165
/// </summary>
@@ -185,7 +198,7 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
185198
updateData[0].PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId;
186199
updateData[0].KeyId = this.KeyId ?? updateData[0].KeyId;
187200
updateData[0].FederatedClientId = this.FederatedClientId ?? updateData[0].FederatedClientId;
188-
updateData[0].RetentionDays = this.EnableSoftDeleteRetention ? (this.RetentionDays ?? 7) : (int?)null;
201+
updateData[0].SoftDeleteRetentionDays = this.EnableSoftDeleteRetention ? (this.SoftDeleteRetentionDays ?? 7) : this.SoftDeleteRetentionDays ==0 ? 0 : (int?)null;
189202

190203
return updateData;
191204
}

src/Sql/Sql/Server/Model/AzureSqlServerModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class AzureSqlServerModel
112112
/// <summary>
113113
/// Gets or sets a value for the soft-delete retention days for the server
114114
/// </summary>
115-
public int? RetentionDays { get; set; }
115+
public int? SoftDeleteRetentionDays { get; set; }
116116

117117
/// <summary>
118118
/// Sets a value for the create mode for the server

src/Sql/Sql/Server/Services/AzureSqlServerAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public AzureSqlServerModel UpsertServer(AzureSqlServerModel model)
143143
PrimaryUserAssignedIdentityId = model.PrimaryUserAssignedIdentityId,
144144
KeyId = model.KeyId,
145145
FederatedClientId = model.FederatedClientId,
146-
RetentionDays = model.RetentionDays,
146+
RetentionDays = model.SoftDeleteRetentionDays,
147147
CreateMode = model.CreateMode,
148148
});
149149

@@ -195,7 +195,7 @@ private static AzureSqlServerModel CreateServerModelFromResponse(Management.Sql.
195195
server.PrimaryUserAssignedIdentityId = resp.PrimaryUserAssignedIdentityId;
196196
server.KeyId = resp.KeyId;
197197
server.FederatedClientId = resp.FederatedClientId;
198-
server.RetentionDays = resp.RetentionDays;
198+
server.SoftDeleteRetentionDays = resp.RetentionDays;
199199

200200
return server;
201201
}

src/Sql/Sql/help/New-AzSqlServer.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,60 @@ PrimaryUserAssignedIdentityId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
103103

104104
This command creates a version 12 Azure SQL Database server with TDE CMK enabled.
105105

106+
### Example 4: Create a new Azure SQL Database server with soft delete retention enabled with default retention days
107+
```powershell
108+
New-AzSqlServer -ResourceGroupName "ResourceGroup01" -Location "Central US" -ServerName "server01" -ServerVersion "12.0" -SqlAdministratorCredentials (Get-Credential) -EnableSoftDeleteRetention $true
109+
```
110+
111+
```output
112+
ResourceGroupName : ResourceGroup01
113+
ServerName : server01
114+
Location : centralus
115+
SqlAdministratorLogin : ramtest
116+
SqlAdministratorPassword :
117+
ServerVersion : 12.0
118+
Tags :
119+
Identity :
120+
FullyQualifiedDomainName : server01.database.windows.net
121+
MinimalTlsVersion : 1.2
122+
PublicNetworkAccess : Enabled
123+
RestrictOutboundNetworkAccess : Disabled
124+
Administrators :
125+
PrimaryUserAssignedIdentityId :
126+
KeyId :
127+
FederatedClientId :
128+
SoftDeleteRetentionDays : 7
129+
```
130+
131+
This command creates a version 12 Azure SQL Database server with soft-delete retention enabled (default 7 days).
132+
133+
### Example 5: Create a new Azure SQL Database server with soft delete retention enabled with 30 retention days
134+
```powershell
135+
New-AzSqlServer -ResourceGroupName "ResourceGroup01" -Location "Central US" -ServerName "server01" -ServerVersion "12.0" -SqlAdministratorCredentials (Get-Credential) -EnableSoftDeleteRetention $true -SoftDeleteRetentionDays 30
136+
```
137+
138+
```output
139+
ResourceGroupName : ResourceGroup01
140+
ServerName : server01
141+
Location : centralus
142+
SqlAdministratorLogin : ramtest
143+
SqlAdministratorPassword :
144+
ServerVersion : 12.0
145+
Tags :
146+
Identity :
147+
FullyQualifiedDomainName : server01.database.windows.net
148+
MinimalTlsVersion : 1.2
149+
PublicNetworkAccess : Enabled
150+
RestrictOutboundNetworkAccess : Disabled
151+
Administrators :
152+
PrimaryUserAssignedIdentityId :
153+
KeyId :
154+
FederatedClientId :
155+
SoftDeleteRetentionDays : 30
156+
```
157+
158+
This command creates a version 12 Azure SQL Database server with soft-delete retention set to 30 days.
159+
106160
## PARAMETERS
107161

108162
### -AsJob

src/Sql/Sql/help/Restore-AzSqlServer.md

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
external help file: Microsoft.Azure.PowerShell.Cmdlets.Sql.dll-Help.xml
33
Module Name: Az.Sql
4-
online version:
4+
online version: https://learn.microsoft.com/powershell/module/az.sql/restore-azsqlserver
55
schema: 2.0.0
66
---
77

88
# Restore-AzSqlServer
99

1010
## SYNOPSIS
11-
{{ Fill in the Synopsis }}
11+
Restores a deleted Azure SQL Database server that is still within its soft-delete retention period
1212

1313
## SYNTAX
1414

@@ -19,24 +19,42 @@ Restore-AzSqlServer -ServerName <String> -Location <String> [-ResourceGroupName]
1919
```
2020

2121
## DESCRIPTION
22-
{{ Fill in the Description }}
22+
The **Restore-AzSqlServer** cmdlet restores a deleted Azure SQL Database server that is still within its soft-delete retention period
2323

2424
## EXAMPLES
2525

2626
### Example 1
2727
```powershell
28-
PS C:\> {{ Add example code here }}
28+
PS C:\> Restore-AzSqlServer -ResourceGroupName "resourcegroup01" -ServerName "server01" -Location "CentralUS"
2929
```
3030

31-
{{ Add example description here }}
31+
```output
32+
ResourceGroupName : resourcegroup01
33+
ServerName : server01
34+
Location : centralus
35+
SqlAdministratorLogin : SqlAdminUser
36+
SqlAdministratorPassword :
37+
ServerVersion : 12.0
38+
Tags :
39+
Identity :
40+
FullyQualifiedDomainName : server01.database.windows.net
41+
MinimalTlsVersion : 1.2
42+
PublicNetworkAccess : Enabled
43+
RestrictOutboundNetworkAccess : Disabled
44+
Administrators :
45+
PrimaryUserAssignedIdentityId :
46+
KeyId :
47+
FederatedClientId :
48+
SoftDeleteRetentionDays : 7
49+
```
3250

3351
## PARAMETERS
3452

3553
### -DefaultProfile
3654
The credentials, account, tenant, and subscription used for communication with Azure.
3755

3856
```yaml
39-
Type: IAzureContextContainer
57+
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
4058
Parameter Sets: (All)
4159
Aliases: AzContext, AzureRmContext, AzureCredential
4260

@@ -51,7 +69,7 @@ Accept wildcard characters: False
5169
The location in which to create the server
5270
5371
```yaml
54-
Type: String
72+
Type: System.String
5573
Parameter Sets: (All)
5674
Aliases:
5775

@@ -62,26 +80,12 @@ Accept pipeline input: False
6280
Accept wildcard characters: False
6381
```
6482
65-
### -ProgressAction
66-
{{ Fill ProgressAction Description }}
67-
68-
```yaml
69-
Type: ActionPreference
70-
Parameter Sets: (All)
71-
Aliases: proga
72-
73-
Required: False
74-
Position: Named
75-
Default value: None
76-
Accept pipeline input: False
77-
Accept wildcard characters: False
78-
```
7983
8084
### -ResourceGroupName
8185
The name of the resource group.
8286
8387
```yaml
84-
Type: String
88+
Type: System.String
8589
Parameter Sets: (All)
8690
Aliases:
8791

@@ -96,7 +100,7 @@ Accept wildcard characters: False
96100
SQL Database server name.
97101
98102
```yaml
99-
Type: String
103+
Type: System.String
100104
Parameter Sets: (All)
101105
Aliases: Name
102106

@@ -111,7 +115,7 @@ Accept wildcard characters: False
111115
Prompts you for confirmation before running the cmdlet.
112116
113117
```yaml
114-
Type: SwitchParameter
118+
Type: System.Management.Automation.SwitchParameter
115119
Parameter Sets: (All)
116120
Aliases: cf
117121

@@ -127,7 +131,7 @@ Shows what would happen if the cmdlet runs.
127131
The cmdlet is not run.
128132
129133
```yaml
130-
Type: SwitchParameter
134+
Type: System.Management.Automation.SwitchParameter
131135
Parameter Sets: (All)
132136
Aliases: wi
133137

@@ -152,3 +156,11 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
152156
## NOTES
153157
154158
## RELATED LINKS
159+
160+
[Get-AzSqlServer](./Get-AzSqlServer.md)
161+
162+
[New-AzSqlServer](./New-AzSqlServer.md)
163+
164+
[Set-AzSqlServer](./Set-AzSqlServer.md)
165+
166+
[SQL Database Documentation](https://learn.microsoft.com/azure/sql-database/)

0 commit comments

Comments
 (0)