Lesson 3 of 4 Backup Solutions

Backing Up Databases in Azure

This lesson explains the backup behaviour of each database service.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe Azure SQL automated backups.
  • Choose a backup approach for SQL Server on a virtual machine.
  • Compare the Cosmos DB backup modes.

Azure SQL Database and SQL Managed Instance

Azure SQL performs automated backups, with no configuration needed: full, differential and transaction log backups, kept in storage managed by Microsoft. Point-in-time restore can recover a database to any moment within a retention period of 1 to 35 days, with a default of 7, into a new database on the same server. The Basic DTU tier is limited to 7 days.

Long-term retention (LTR) keeps specified full backups for up to 10 years, with weekly, monthly and yearly rules, in order to meet regulatory requirements. Backup storage redundancy can be set to LRS, ZRS or GRS. Geo-restore uses geo-replicated backups to restore a database in any region, which gives inexpensive disaster recovery with a recovery time of minutes to hours. Deleted databases can also be restored, within their retention period.

Hyperscale differs because its backups are based on storage snapshots, so restores are fast regardless of database size, a useful point when a very large database has a tight RTO.

Fill in the value

Azure SQL backup numbers

Exam skills 3.1.3

Recall the backup limits of Azure SQL.

Log in to try this activity Interactive activities are free with an account.

SQL Server on Azure virtual machines

For SQL Server on a virtual machine, Azure Backup provides an application-aware solution, using a Recovery Services vault, without any backup infrastructure. It supports full, differential and transaction log backups, with log backups as frequent as every 15 minutes, which gives point-in-time recovery. It is the recommendation when the requirement is central management and long retention. Alternatively, SQL Server can back up directly to Azure Blob Storage with the backup to URL feature, keeping DBA-managed scripts. Taking only a virtual machine snapshot would not give point-in-time recovery for the database.

Scenario questions

SQL Server on VMs

Exam skills 3.1.3

Choose how to back up SQL Server running on Azure VMs.

Log in to try this activity Interactive activities are free with an account.

Azure Database for PostgreSQL and MySQL

Flexible servers take automatic backups, and the default retention is 7 days, configurable up to 35. Point-in-time restore creates a new server. Zone-redundant backup storage protects these backups where available, and geo-redundant backup storage can enable geo-restore in another region.

For retention beyond 35 days, Azure Backup can protect Azure Database for PostgreSQL in a Backup vault, which meets longer compliance requirements, and it supports cross-region restore. The equivalent preview for MySQL flexible server is currently paused, so a design should not rely on it for new backups.

Azure Cosmos DB

Cosmos DB has two backup modes. Periodic backup takes full backups at a configured interval and keeps them for a configured period; restoring generally requires a support request. Continuous backup allows self-service point-in-time restore, with tiers that retain 7, 30 or 35 days of history. The 7-day tier has no extra backup storage charge, and the 30-day and 35-day tiers incur one. Continuous backup does not support the Apache Cassandra API.

Azure Backup also offers vaulted backup for Cosmos DB in a Backup vault, with long-term retention of up to 10 years; the Azure Backup documentation lists it as a preview. A restore creates a new account or a new container rather than overwriting the data. Replicas in multiple regions are not a backup, since a mistaken change replicates immediately.

True or false

Cosmos DB backup modes

Exam skills 3.1.3

Check the Cosmos DB backup options.

Log in to try this activity Interactive activities are free with an account.

Comparing database backup

The following table recaps the default behaviour of each service.

ServiceDefault protectionExtending retention
Azure SQL Database and Managed InstanceAutomatic, 1-35 days of point-in-time restoreLong-term retention up to 10 years
SQL Server on Azure VMsNone by defaultAzure Backup, with log backups every 15 minutes
PostgreSQL flexible serverAutomatic, 7 days by default, up to 35Azure Backup in a Backup vault
MySQL flexible serverAutomatic, 1-35 daysCustomer-managed exports
Azure Cosmos DBPeriodic backup by defaultContinuous backup for self-service restore; vaulted backup (preview) for long-term retention

The following diagram compares the native backup protection of Azure SQL Database with that of SQL Server on an Azure VM.

Native retention for two databases. Azure SQL Database keeps point-in-time restore for 30 days and a long-term retention policy holds month-end copies for seven years. SQL Server on an Azure virtual machine uses Azure Backup for SQL Server in Azure VMs, with log backups every 15 minutes and central reporting.
The scenario is illustrative.

Designing database recovery

Automated backups make recovery possible, but the design must still consider how long a restore takes. A point-in-time restore creates a new database, so its duration depends on the size of the database and the amount of log to replay, and it cannot be assumed to meet a short RTO, except on Hyperscale, whose restores use snapshots. An application must also be pointed at the restored database, by changing a connection string or by renaming databases, and this step should be included in a recovery runbook.

Backup storage has its own cost and residency implications. Geo-redundant backup storage allows geo-restore, but it places copies in another region, which must be acceptable under any data residency rule. Zone-redundant or locally redundant backup storage keeps data in one region, and it is the option for a strict residency requirement, in which case regional recovery must come from elsewhere. Long-term retention backups are charged for the storage they consume, so rules should be set according to the actual regulatory need.

Choosing between failover and restore

Replication and backup answer different questions, and a database design generally needs both. A failover group protects against the loss of a region, within seconds or minutes, and it keeps the latest data, including any mistakes. Point-in-time restore goes back to the moment before a mistake, but it takes longer and involves a new database. If a developer drops a table, failing over would not help, as the drop has already been replicated, so a restore is required. If a region fails, a restore would work, but it would be far slower than a failover, with more data loss. Recovery plans should say clearly which path applies to which event.

Sort into groups

Failover or restore?

Exam skills 3.1.3

Decide whether each event calls for a failover or a point-in-time restore.

Log in to try this activity Interactive activities are free with an account.
Worked example

Meeting retention rules

A finance company must retain month-end copies of an Azure SQL database for seven years, and restore to any point in the last 30 days. A separate SQL Server on an Azure virtual machine must have an RPO of 15 minutes, with central reporting across backups. What should you recommend?

For Azure SQL Database, set the point-in-time retention to 30 days, and add a long-term retention policy with a monthly rule held for seven years. This uses native features, with no additional service.

For the virtual machine, use Azure Backup for SQL Server in Azure VMs, with transaction log backups every 15 minutes. A daily virtual machine backup would give a far worse RPO, and exporting BACPAC files by script would add effort, and would not provide point-in-time recovery.

Check yourself

Is a Cosmos DB account with multiple regions backed up by virtue of its replicas?

Show answer

No. A mistaken change replicates immediately, so a backup mode is still needed for recovery.

Exam Tips

Remember for the exam

  • Azure SQL: point-in-time restore 1-35 days, long-term retention up to 10 years.
  • Azure Backup for SQL in a VM supports log backups every 15 minutes.
  • Cosmos DB continuous backup gives self-service restore, with 7, 30 or 35-day tiers.
  • A restore usually creates a new database or account.