Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions src/Sql/Sql.Test/ScenarioTests/DatabaseBackupTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -443,55 +443,73 @@ function Test-RemoveDatabaseRestorePoint
function Test-ShortTermRetentionPolicy
{
# Setup
$location = Get-Location "Microsoft.Sql" "servers" "West US 2"
$rg = Create-ResourceGroupForTest $location
$server = Create-ServerForTest $rg $location
$location = "southeast asia"
$rg = "PowershellStageResourceGroup"
$server = "pssqlserverfortest"

try
{
# Create db with default values
$databaseName = Get-DatabaseName
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
$db = New-AzSqlDatabase -ResourceGroupName $rg -ServerName $server -DatabaseName $databaseName -Force:$true

# Test default parameter set
$retention = 28
$policy = Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -RetentionDays $retention
# Test GET
$defaultRetention = 7
# After we configure Backup Service's default DiffBackupIntervalInHours as 24 hours for new created databases, $defaultDiffbackupinterval should be 24.
$defaultDiffbackupinterval = 12
$policy = Get-AzSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName $rg -ServerName $server -DatabaseName $databaseName
Assert-AreEqual $policy.Count 1
Assert-AreEqual $retention $policy[0].RetentionDays
$policy = Get-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
Assert-AreEqual $defaultRetention $policy[0].RetentionDays
Assert-AreEqual $defaultDiffbackupinterval $policy[0].DiffBackupIntervalInHours

# Test SET
$retention = 6
$diffbackupinterval = 24
$policy = Set-AzSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName $rg -ServerName $server -DatabaseName $databaseName -RetentionDays $retention -DiffBackupIntervalInHours $diffbackupinterval

Assert-AreEqual $policy.Count 1
Assert-AreEqual $retention $policy[0].RetentionDays
Assert-AreEqual $diffbackupinterval $policy[0].DiffBackupIntervalInHours

# Test InputObject
$retention = 21
$policy = Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -AzureSqlDatabase $db -RetentionDays $retention
$retention = 7
$diffbackupinterval = 12
$policy = Set-AzSqlDatabaseBackupShortTermRetentionPolicy -AzureSqlDatabase $db -RetentionDays $retention -DiffBackupIntervalInHours $diffbackupinterval
Assert-AreEqual 1 $policy.Count
Assert-AreEqual $retention $policy[0].RetentionDays
$policy = Get-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -AzureSqlDatabase $db
Assert-AreEqual $diffbackupinterval $policy[0].DiffBackupIntervalInHours
$policy = Get-AzSqlDatabaseBackupShortTermRetentionPolicy -AzureSqlDatabase $db
Assert-AreEqual 1 $policy.Count
Assert-AreEqual $retention $policy[0].RetentionDays
Assert-AreEqual $diffbackupinterval $policy[0].DiffBackupIntervalInHours

# Test ResourceId
$retention = 14
$retention = 6
$diffbackupinterval = 24
$resourceId = $db.ResourceId + "/backupShortTermRetentionPolicies/default"
$policy = Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -ResourceId $resourceId -RetentionDays $retention
$policy = Set-AzSqlDatabaseBackupShortTermRetentionPolicy -ResourceId $resourceId -RetentionDays $retention -DiffBackupIntervalInHours $diffbackupinterval
Assert-AreEqual 1 $policy.Count
Assert-AreEqual $retention $policy[0].RetentionDays
$policy = Get-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -ResourceId $resourceId
Assert-AreEqual $diffbackupinterval $policy[0].DiffBackupIntervalInHours
$policy = Get-AzSqlDatabaseBackupShortTermRetentionPolicy -ResourceId $resourceId
Assert-AreEqual 1 $policy.Count
Assert-AreEqual $retention $policy[0].RetentionDays
Assert-AreEqual $diffbackupinterval $policy[0].DiffBackupIntervalInHours

# Test Piping
$retention = 7
$policy = $db | Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -RetentionDays $retention
$diffbackupinterval = 12
$policy = $db | Set-AzSqlDatabaseBackupShortTermRetentionPolicy -RetentionDays $retention -DiffBackupIntervalInHours $diffbackupinterval
Assert-AreEqual 1 $policy.Count
Assert-AreEqual $retention $policy[0].RetentionDays
$policy = $db | Get-AzureRmSqlDatabaseBackupShortTermRetentionPolicy
Assert-AreEqual $diffbackupinterval $policy[0].DiffBackupIntervalInHours
$policy = $db | Get-AzSqlDatabaseBackupShortTermRetentionPolicy
Assert-AreEqual 1 $policy.Count
Assert-AreEqual $retention $policy[0].RetentionDays
Assert-AreEqual $diffbackupinterval $policy[0].DiffBackupIntervalInHours
}
finally
{
Remove-ResourceGroupForTest $rg
Remove-AzSqlDatabase -ResourceGroupName $rg -ServerName $server -DatabaseName $databaseName
}
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Sql/Sql.Test/Sql.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.21.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.44.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.45.0-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 1 addition & 35 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Update Azure Paired Regions URL in Backup Storage Redundancy Warnings

## Version 2.11.0
* Added BackupStorageRedundancy to the following:
- `Restore-AzureRmSqlDatabase`
- `New-AzSqlDatabaseCopy`
- `New-AzSqlDatabaseSecondary`
* Removed case sensitivity for BackupStorageRedundancy parameter for all SQL DB references
* Updated BackupStorageRedundancy warning message names
* Added support for Managed HSM Uris for SQL DB and Managed Instance

## Version 2.10.1
* Added warning for BackupStorageRedundancy configuration in select regions in `New-AzSqlDatabase` (Ignore Case for BackupStorageRedundancy configuration input)
* Fixed for bug in `New-AzSqlDatabaseExport`
* Removed case sensitivity for BackupStorageRedundancy parameter for `New-AzSqlInstance`

## Version 2.10.0
* Added BackupStorageRedundancy to `New-AzSqlInstance` and `Get-AzSqlInstance`
* Added cmdlet `Get-AzSqlServerActiveDirectoryOnlyAuthentication`
* Added cmdlet `Enable-AzSqlServerActiveDirectoryOnlyAuthentication`
* Added Force parameter to `New-AzSqlInstance`
* Added cmdlets for Managed Database Log Replay service
- `Start-AzSqlInstanceDatabaseLogReplay`
- `Get-AzSqlInstanceDatabaseLogReplay`
- `Complete-AzSqlInstanceDatabaseLogReplay`
- `Stop-AzSqlInstanceDatabaseLogReplay`
* Added cmdlet `Get-AzSqlInstanceActiveDirectoryOnlyAuthentication`
* Added cmdlet `Enable-AzSqlInstanceActiveDirectoryOnlyAuthentication`
* Added cmdlet `Disable-AzSqlInstanceActiveDirectoryOnlyAuthentication`
* Updated cmdlets `New-AzSqlDatabaseImport` and `New-AzSqlDatabaseExport` to support network isolation functionality
* Added cmdlet `New-AzSqlDatabaseImportExisting`
* Updated Databases cmdlets to support backup storage type specification
* Added Force parameter to `New-AzSqlDatabase`
* Updated ActiveDirectoryOnlyAuthentication cmdlets for server and instance to include ResourceId and InputObject
* Added support for Managed HSM Uris for SQL DB and Managed Instance
* Added DiffBackupIntervalInHours to `Set-AzSqlDatabaseBackupShortTermRetentionPolicy`
Copy link
Member

@isra-fel isra-fel Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that the change logs of past versions were deleted accidently in this PR. Please be careful when you submit another PR. Thanks


## Version 2.9.1
* Fixed potential server name case insensitive error in `New-AzSqlServer` and `Set-AzSqlServer`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.Sql.Backup.Model;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Sql.Backup.Cmdlet
{
Expand All @@ -28,12 +29,17 @@ public class SetAzureRmSqlDatabaseBackupShortTermRetentionPolicy : AzureSqlDatab
/// <summary>
/// Gets or sets backup retention days.
/// </summary>
[Parameter(Mandatory = true,
Position = 3,
[Parameter(Mandatory = false,
HelpMessage = "The backup retention setting, in days.")]
[ValidateNotNullOrEmpty]
public int RetentionDays{ get; set; }
public int RetentionDays { get; set; }

/// <summary>
/// Gets or sets differential backup interval hours.
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The differential backup interval, in hours.")]
public int DiffBackupIntervalInHours { get; set; }

/// <summary>
/// Get the entities from the service
/// </summary>
Expand Down Expand Up @@ -64,7 +70,10 @@ protected override IEnumerable<AzureSqlDatabaseBackupShortTermRetentionPolicyMod
ResourceGroupName,
ServerName,
DatabaseName,
new Management.Sql.Models.BackupShortTermRetentionPolicy(retentionDays: RetentionDays))
new Management.Sql.Models.BackupShortTermRetentionPolicy(
retentionDays: this.IsParameterBound(c => c.RetentionDays) ? RetentionDays : null as int?,
diffBackupIntervalInHours: this.IsParameterBound(c => c.DiffBackupIntervalInHours) ? DiffBackupIntervalInHours : null as int?)
)
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;

namespace Microsoft.Azure.Commands.Sql.Backup.Model
{
public class AzureSqlDatabaseBackupShortTermRetentionPolicyModel
Expand All @@ -34,7 +36,12 @@ public class AzureSqlDatabaseBackupShortTermRetentionPolicyModel
/// <summary>
/// Gets or sets the retention days of this policy.
/// </summary>
public int RetentionDays { get; set; }
public int? RetentionDays { get; set; }

/// <summary>
/// Gets or sets the differential backup interval of this policy.
/// </summary>
public int? DiffBackupIntervalInHours { get; set; }

/// <summary>
/// Construct AzureSqlDatabaseBackupShortTermRetentionPolicyModel from Management.Sql.BackupShortTermRetentionPolicy object
Expand All @@ -44,10 +51,16 @@ public class AzureSqlDatabaseBackupShortTermRetentionPolicyModel
/// <param name="policy"></param>
public AzureSqlDatabaseBackupShortTermRetentionPolicyModel(string resourceGroup, string serverName, string databaseName, Management.Sql.Models.BackupShortTermRetentionPolicy policy)
{
if (policy.RetentionDays == null && policy.DiffBackupIntervalInHours == null)
{
throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Sql.Properties.Resources.SetAzSqlDatabaseBackupShortTermRetentionInvalidParameters, "RetentionDays", "DiffBackupIntervalInHours"));
}

ResourceGroupName = resourceGroup;
ServerName = serverName;
DatabaseName = databaseName;
RetentionDays = policy.RetentionDays.Value;
DiffBackupIntervalInHours = policy.DiffBackupIntervalInHours.Value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ internal AzureSqlDatabaseBackupShortTermRetentionPolicyModel SetDatabaseBackupSh
databaseName,
new Management.Sql.Models.BackupShortTermRetentionPolicy()
{
RetentionDays = model.RetentionDays
RetentionDays = model.RetentionDays,
DiffBackupIntervalInHours = model.DiffBackupIntervalInHours
});

return new AzureSqlDatabaseBackupShortTermRetentionPolicyModel(resourceGroup, serverName, databaseName, baPolicy);
Expand Down
11 changes: 10 additions & 1 deletion src/Sql/Sql/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Sql/Sql/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,7 @@
<data name="BackupRedundancyNotChosenTakeSourceWarning" xml:space="preserve">
<value>You have not specified the value for backup storage redundancy which will default to the source's backup storage redundancy. To learn more about Azure Paired Regions visit aka.ms/azure-ragrs-regions.</value>
</data>
<data name="SetAzSqlDatabaseBackupShortTermRetentionInvalidParameters" xml:space="preserve">
<value>Parameter '{0}' and '{1}' both being null is not allowed.</value>
</data>
</root>
2 changes: 1 addition & 1 deletion src/Sql/Sql/Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.44.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.45.0-preview" />
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
</ItemGroup>

Expand Down
20 changes: 10 additions & 10 deletions src/Sql/Sql/help/Get-AzSqlDatabaseBackupShortTermRetentionPolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ Get-AzSqlDatabaseBackupShortTermRetentionPolicy -ResourceId <String> [-DefaultPr

## DESCRIPTION
The **Get-AzSqlDatabaseBackupShortTermRetentionPolicy** cmdlet gets the short term retention policy registered to this database.
The policy is the retention period, in days, for point-in-time restore backups.
The policy is the retention period in days and differential backup interval in hours, for point-in-time restore backups.

## EXAMPLES

### Example 1
```powershell
PS C:\> Get-AzSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName resourcegroup01 -ServerName server01 -DatabaseName database01

ResourceGroupName ServerName DatabaseName RetentionDays
----------------- ---------- ------------ -------------
resourcegroup01 server01 database01 35
ResourceGroupName ServerName DatabaseName RetentionDays DiffBackupIntervalInHours
----------------- ---------- ------------ ------------- -------------------------
resourcegroup01 server01 database01 7 24
```

This command gets the short term retention policy for database01.
Expand All @@ -51,9 +51,9 @@ This command gets the short term retention policy for database01.
```powershell
PS C:\> Get-AzSqlDatabase -ResourceGroupName resourcegroup01 -ServerName server01 -DatabaseName database01 | Get-AzSqlDatabaseBackupShortTermRetentionPolicy

ResourceGroupName ServerName DatabaseName RetentionDays
----------------- ---------- ------------ -------------
resourcegroup01 server01 database01 35
ResourceGroupName ServerName DatabaseName RetentionDays DiffBackupIntervalInHours
----------------- ---------- ------------ ------------- -------------------------
resourcegroup01 server01 database01 7 24
```

This command gets the short term retention policy for database01 via piping in a database object.
Expand Down Expand Up @@ -84,7 +84,7 @@ Parameter Sets: PolicyByResourceServerDatabaseSet
Aliases:

Required: True
Position: 2
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Expand Down Expand Up @@ -114,7 +114,7 @@ Parameter Sets: PolicyByResourceServerDatabaseSet
Aliases:

Required: True
Position: 0
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Expand Down Expand Up @@ -144,7 +144,7 @@ Parameter Sets: PolicyByResourceServerDatabaseSet
Aliases:

Required: True
Position: 1
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Expand Down
Loading