Backup & Restore for Azure SQL Database
Azure SQL Database provides automated backups, point‑in‑time restore, and geo‑redundant storage. This tutorial walks you through creating a manual backup using export, and restoring it to a new database.
Prerequisites
- An Azure subscription with a SQL Database instance.
- Azure CLI or PowerShell installed.
- Permissions:
db_owneron the source database andContributorrole on the resource group.
Step 1 – Export a BACPAC (Logical Backup)
You can export a BACPAC file via the Azure portal, Azure CLI, or PowerShell. Below is the Azure CLI method.
az sql db export \
--resource-group MyResourceGroup \
--server myazuresqlserver \
--name MyDatabase \
--admin-user adminUser \
--admin-password <Password> \
--storage-key <StorageAccountKey> \
--storage-key-type StorageAccessKey \
--storage-uri https://mystorageaccount.blob.core.windows.net/backups/MyDatabase.bacpac
Step 2 – Import (Restore) the BACPAC
Import the BACPAC into a new database using Azure CLI:
az sql db import \
--resource-group MyResourceGroup \
--server myazuresqlserver \
--name RestoredDatabase \
--admin-user adminUser \
--admin-password <Password> \
--storage-key <StorageAccountKey> \
--storage-key-type StorageAccessKey \
--storage-uri https://mystorageaccount.blob.core.windows.net/backups/MyDatabase.bacpac
Step 3 – Point‑in‑Time Restore (PITR)
For automated backups, you can restore to any point within the retention period (up to 35 days).
az sql db restore \
--resource-group MyResourceGroup \
--server myazuresqlserver \
--name RestoredPITR \
--dest-name MyDatabase_Restore \
--time "2025-09-15T12:30:00Z"
Verifying the Restore
Connect to the restored database and verify data integrity.
SELECT TOP 100 *
FROM dbo.ImportantTable
ORDER BY CreatedDate DESC;
Automation with PowerShell
Below is a PowerShell script that automates export and import.
# Export BACPAC
$exportParams = @{
ResourceGroupName = 'MyResourceGroup'
ServerName = 'myazuresqlserver'
DatabaseName = 'MyDatabase'
StorageKeyType = 'StorageAccessKey'
StorageKey = $env:STORAGE_KEY
StorageUri = 'https://mystorageaccount.blob.core.windows.net/backups/MyDatabase.bacpac'
AdministratorLogin = 'adminUser'
AdministratorLoginPassword = (ConvertTo-SecureString $env:SQL_PASSWORD -AsPlainText -Force)
}
Export-AzSqlDatabase @exportParams
# Import BACPAC
$importParams = $exportParams.Clone()
$importParams.DatabaseName = 'RestoredDatabase'
Import-AzSqlDatabase @importParams
Next Steps
- Configure long‑term retention (LTR) for compliance.
- Set up geo‑redundant backups across regions.
- Automate backup monitoring with Azure Monitor alerts.