Exercise - Configure long-term retention policies

Completed

Your retail organization must comply with data protection regulations in your jurisdiction. You need to configure a long-term retention (LTR) policy in Azure SQL Database to meet these requirements.

Let's use the Azure portal to set up a policy and then check it in PowerShell. You need to set up the following retention policy to meet your regulatory requirements:

Retention period Length
Weekly Eight weeks
Monthly 12 months
Yearly Five years

Use the Azure portal to configure long-term retention

Let's start by configuring the LTR policy by using the portal.

  1. On the Azure portal menu or from the Home page, select All resources, and then select erpserver-NNNN.

  2. Under Data Management, select Backups.

  3. In the list of databases, select sql-erp-db. Select the Retention policies tab, and then select Configure policies.

  4. In the Long-term retention section, enter the value 8 and select Week(s) under Weekly LTR Backups.

  5. Under Monthly LTR Backups, enter the value 12 and select Month(s).

  6. Under Yearly LTR Backups, enter the value 5 and select Year(s).

    Screenshot of the configure policies panel used to create a yearly retention policy.

  7. Select Apply, and then select Yes.

Use PowerShell to configure long-term retention

You can also configure LTR policies by using PowerShell.

  1. In Azure Cloud Shell, run this command to set a variable to the value of your SQL Server instance:

    $sqlserver=Get-AzSqlServer
    
  2. To view long-term retention policies for the database server, run this command:

    Get-AzSqlDatabase `
        -ResourceGroupName <rgn>[sandbox resource group name]</rgn> `
        -ServerName $sqlserver.ServerName `
        | Get-AzSqlDatabaseLongTermRetentionPolicy
    

    This step outputs the retention policies for all databases on the server:

    Note

    You might see a message display after the output: Long Term Retention is not supported : Not supported for master. This message doesn't affect completion of this module.

  3. Run this command to view the LTR policy for the sql-erp-db database:

    Get-AzSqlDatabaseBackupLongTermRetentionPolicy `
        -ServerName $sqlserver.ServerName `
        -DatabaseName sql-erp-db `
        -ResourceGroupName <rgn>[sandbox resource group name]</rgn>
    
  4. Now let's configure the rest of the policy to meet the requirements specified earlier. To configure an LTR policy via PowerShell, run this command:

    Set-AzSqlDatabaseBackupLongTermRetentionPolicy `
        -ServerName $sqlserver.ServerName `
        -DatabaseName sql-erp-db `
        -ResourceGroupName <rgn>[sandbox resource group name]</rgn> `
        -WeeklyRetention P8W `
        -MonthlyRetention P12M `
        -YearlyRetention P5Y `
        -WeekOfYear 1
    
  5. To check that you've applied the new policy, run this command again:

    Get-AzSqlDatabaseBackupLongTermRetentionPolicy `
        -ServerName $sqlserver.ServerName `
        -DatabaseName sql-erp-db `
        -ResourceGroupName <rgn>[sandbox resource group name]</rgn>
    

    You should see the following policy configured. It enables a weekly retention of eight weeks, a monthly retention of 12 months, and a yearly retention of five years for the first backup of the year.

    ResourceGroupName : <rgn>[sandbox resource group name]</rgn>
    ServerName        : erpserver-25078
    DatabaseName      : sql-erp-db
    WeeklyRetention   : P8W
    MonthlyRetention  : P12M
    YearlyRetention   : P5Y
    WeekOfYear        : 1
    Location          :
    
  6. You can also confirm the retention period in the portal. Open the Azure portal menu or from the Home page, select All resources, and then select ERPServer.

  7. Under Data management, select Backups, then select Retention policies. In the list of databases, check the sql-erp-db long-term retention properties.

    Screenshot of completed long-term retention policy settings.

You've now configured a retention policy and validated that the policy meets your organizational and regulatory requirements.