Azure SQL Database Backup and Restore

This document provides a comprehensive guide to understanding and utilizing the backup and restore capabilities of Azure SQL Database. Azure SQL Database automatically backs up your data, enabling you to recover your database to any point in time within your configured retention period.

Understanding Automatic Backups

Azure SQL Database performs full, differential, and transaction log backups automatically. You don't need to manage these backups yourself. The service handles the infrastructure, storage, and backup schedule. The retention period for these backups depends on the service tier and configuration of your SQL Database.

Backup Types and Schedules:

Restore Options

Azure SQL Database offers several restore scenarios:

1. Point-in-Time Restore (PITR)

This is the most common restore operation. You can restore your database to any specific point in time within the available backup retention period. This is invaluable for recovering from accidental data modifications, corruption, or user errors.

Key Features:

2. Geo-Restore

If your database is unavailable due to a regional outage, you can restore it from a geo-replicated backup to a database in any available Azure region. This is a crucial part of your disaster recovery strategy.

Prerequisites:

3. Long-Term Retention (LTR)

For compliance or archival purposes, you can configure long-term retention policies to store backups for extended periods (up to 10 years). These backups are stored in separate geo-redundant storage and can be accessed for recovery when needed.

How to Perform a Restore

Restoring a database can be accomplished using the Azure portal, Azure PowerShell, or Azure CLI.

Using the Azure Portal:

  1. Navigate to your Azure SQL Database resource in the Azure portal.
  2. In the left-hand menu, under "Data management," select "Restore."
  3. Choose the restore type (Point-in-time restore, Geo-restore).
  4. For Point-in-time restore, select the desired recovery point.
  5. Specify the new database name, server, and other configuration settings.
  6. Click "Review + create," then "Create" to start the restore process.

Using Azure PowerShell:

Example for Point-in-time Restore:


$resourceGroupName = "YourResourceGroupName"
$serverName = "YourServerName"
$databaseName = "YourDatabaseName"
$restorePointDateTime = "2023-10-27T10:30:00Z" # Example: October 27, 2023 at 10:30 UTC
$newDatabaseName = "YourRestoredDatabaseName"
$newServerName = "YourTargetServerName" # Can be the same as $serverName

Restore-AzSqlDatabase -FromPointInTimeBackup -ResourceGroupName $resourceGroupName -ServerName $serverName -DatabaseName $databaseName -PointInTime $restorePointDateTime -TargetDatabaseName $newDatabaseName -TargetServerName $newServerName
            

Using Azure CLI:

Example for Point-in-time Restore:


az sql db restore --resource-group YourResourceGroupName --server YourServerName --name YourDatabaseName --dest-name YourRestoredDatabaseName --time "2023-10-27T10:30:00Z" --dest-server YourTargetServerName
            

Restoring to a Different Server

When performing a restore, you can choose to restore the database to a different Azure SQL Database server. This is useful for creating development/test environments, migrating data, or isolating restored data.

Considerations for Restore Operations

Important Note: Always test your restore procedures regularly to ensure they function as expected and to familiarize your team with the process.

Next Steps

Explore the following resources for more detailed information: