Skip to content

Commit 8863670

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

File tree

11 files changed

+221
-105
lines changed

11 files changed

+221
-105
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: 18 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: 6 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>
@@ -766,4 +769,7 @@
766769
<data name="ForwardMigrationWithGeoDRInfo" xml:space="preserve">
767770
<value>Changing the service tier to Hyperscale also converts the geo-secondary replica to Hyperscale. For more information, see https://go.microsoft.com/fwlink/?linkid=2314103</value>
768771
</data>
772+
<data name="DeletedServerNotFound" xml:space="preserve">
773+
<value>No deleted server named '{0}' found in resource group '{1}' that can be restored.</value>
774+
</data>
769775
</root>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public class NewAzureSqlServer : AzureSqlServerCmdletBase
170170
/// </summary>
171171
[Parameter(Mandatory = false,
172172
HelpMessage = "Specifies the soft-delete retention days for the server.")]
173+
[ValidateRange(0, 35)]
173174
public int? SoftDeleteRetentionDays { get; set; }
174175

175176
/// <summary>
@@ -194,6 +195,12 @@ public override void ExecuteCmdlet()
194195
throw new PSArgumentException(Properties.Resources.MissingSQLAdministratorCredentials, "SqlAdministratorCredentials");
195196
}
196197

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

@@ -260,7 +267,7 @@ public override void ExecuteCmdlet()
260267
Login = this.ExternalAdminName,
261268
Sid = this.ExternalAdminSID
262269
},
263-
RetentionDays = (this.EnableSoftDeleteRetention && !this.SoftDeleteRetentionDays.HasValue) ? 7 : this.SoftDeleteRetentionDays
270+
SoftDeleteRetentionDays = (this.EnableSoftDeleteRetention && !this.SoftDeleteRetentionDays.HasValue) ? 7 : this.SoftDeleteRetentionDays
264271
});
265272
return newEntity;
266273
}

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public class RestoreAzureSqlServer : AzureSqlServerCmdletBase
5454
/// </summary>
5555
public override void ExecuteCmdlet()
5656
{
57-
if (this.ServerName == "")
58-
{
59-
throw new PSArgumentException("Missing ServerName");
60-
}
61-
6257
base.ExecuteCmdlet();
6358
}
6459

@@ -85,7 +80,7 @@ public override void ExecuteCmdlet()
8580
}
8681
catch (CloudException ex)
8782
{
88-
if (ex.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
83+
if (ex.Response?.StatusCode != System.Net.HttpStatusCode.NotFound)
8984
{
9085
// Unexpected exception encountered
9186
throw;
@@ -99,21 +94,21 @@ public override void ExecuteCmdlet()
9994
var deletedServer = ModelAdapter.GetDeletedServer(this.ResourceGroupName, this.ServerName);
10095
if (deletedServer == null)
10196
{
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");
97+
throw new PSArgumentException(
98+
string.Format(Properties.Resources.DeletedServerNotFound,
99+
this.ServerName, this.ResourceGroupName),
100+
"ServerName");
106101
}
107102

108103
// Deleted server exists and can be restored
109104
return null;
110105
}
111106
catch (CloudException ex)
112107
{
113-
if (ex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
108+
if (ex.Response?.StatusCode == System.Net.HttpStatusCode.NotFound)
114109
{
115110
throw new PSArgumentException(
116-
string.Format("No deleted server named '{0}' found in resource group '{1}' that can be restored.",
111+
string.Format(Properties.Resources.DeletedServerNotFound,
117112
this.ServerName, this.ResourceGroupName),
118113
"ServerName");
119114
}

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,29 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
138138
/// </summary>
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.")]
141+
[ValidateRange(0, 35)]
141142
[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; }
143+
public int? SoftDeleteRetentionDays { get; set; }
143144

144145
/// <summary>
145146
/// Defines whether it is ok to skip the requesting of rule removal confirmation
146147
/// </summary>
147148
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
148149
public SwitchParameter Force { get; set; }
149150

151+
/// <summary>
152+
/// Overriding to add warning message
153+
/// </summary>
154+
public override void ExecuteCmdlet()
155+
{
156+
// SoftDeleteRetentionDays depends on EnableSoftDeleteRetention; if days are provided but soft-delete is not enabled, fail early.
157+
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays > 0 && !this.EnableSoftDeleteRetention)
158+
{
159+
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDeleteRetention, "EnableSoftDeleteRetention");
160+
}
161+
162+
base.ExecuteCmdlet();
163+
}
150164
/// <summary>
151165
/// Get the server to update
152166
/// </summary>
@@ -185,7 +199,24 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
185199
updateData[0].PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId;
186200
updateData[0].KeyId = this.KeyId ?? updateData[0].KeyId;
187201
updateData[0].FederatedClientId = this.FederatedClientId ?? updateData[0].FederatedClientId;
188-
updateData[0].RetentionDays = this.EnableSoftDeleteRetention ? (this.RetentionDays ?? 7) : (int?)null;
202+
if (this.EnableSoftDeleteRetention)
203+
{
204+
// If enabling soft-delete retention, use the explicitly provided value or default to 7 days if none provided.
205+
updateData[0].SoftDeleteRetentionDays = this.SoftDeleteRetentionDays ?? 7;
206+
}
207+
else
208+
{
209+
// If not enabling, only explicitly set retention to 0 when the caller provided 0.
210+
// Otherwise, leave as null so the service preserves the existing retention setting.
211+
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays.Value == 0)
212+
{
213+
updateData[0].SoftDeleteRetentionDays = 0;
214+
}
215+
else
216+
{
217+
updateData[0].SoftDeleteRetentionDays = null;
218+
}
219+
}
189220

190221
return updateData;
191222
}

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: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ New-AzSqlServer -ServerName <String> [-SqlAdministratorCredentials <PSCredential
2222
[-EnableActiveDirectoryOnlyAuthentication] [-ExternalAdminName <String>] [-ExternalAdminSID <Guid>]
2323
[-FederatedClientId <Guid>] [-EnableSoftDeleteRetention <Boolean>] [-SoftDeleteRetentionDays <Int32>]
2424
[-CreateMode <String>] [-ResourceGroupName] <String> [-DefaultProfile <IAzureContextContainer>]
25-
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
25+
[-WhatIf] [-Confirm] [<CommonParameters>]
2626
```
2727

2828
## DESCRIPTION
@@ -49,8 +49,6 @@ This command creates a version 12 Azure SQL Database server.
4949

5050
### Example 2: Create a new Azure SQL Database server with External (Microsoft Entra ID) Administrator, Microsoft Entra-only Authentication and no SqlAdministratorCredentials
5151
<!-- Skip: Output cannot be splitted from code -->
52-
53-
5452
```powershell
5553
New-AzSqlServer -ResourceGroupName "ResourceGroup01" -Location "Central US" -ServerName "server01" -ServerVersion "12.0" -ExternalAdminName DummyLogin -EnableActiveDirectoryOnlyAuthentication
5654
ResourceGroupName : resourcegroup01
@@ -103,6 +101,60 @@ PrimaryUserAssignedIdentityId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx
103101

104102
This command creates a version 12 Azure SQL Database server with TDE CMK enabled.
105103

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

108160
### -AsJob
@@ -316,21 +368,6 @@ Accept pipeline input: False
316368
Accept wildcard characters: False
317369
```
318370
319-
### -ProgressAction
320-
{{ Fill ProgressAction Description }}
321-
322-
```yaml
323-
Type: System.Management.Automation.ActionPreference
324-
Parameter Sets: (All)
325-
Aliases: proga
326-
327-
Required: False
328-
Position: Named
329-
Default value: None
330-
Accept pipeline input: False
331-
Accept wildcard characters: False
332-
```
333-
334371
### -PublicNetworkAccess
335372
Takes a flag, enabled/disabled, to specify whether public network access to server is allowed or not.
336373
When disabled, only connections made through Private Links can reach this server.

0 commit comments

Comments
 (0)