How To Monitor SQL Server Automated Backup in Microsoft AzureStorage #Azure #SQLServer

3 Min. Read


Azure Automated Backup allows you to schedule regular backups for all databases on a SQL Server Azure IaaS VM. Backups are stored in Azure storage for up to 30 days. SQL Server 2016 and higher VMs offer more customization options with Automated Backup v2. These improvements include:

  • System database backups
  • Manual backup schedule and time window
  • Full and log file backup frequency

For more information, check my previous article on How to backup SQL Server named instance to Microsoft Azure Blob Storage.

Once you have SQL Server managed backup up and running in Azure, then you need to make sure that backup is working properly and you don’t have any issue.

Starting with SQL Server 2014 and later, SQL Server Managed Backup to Microsoft Azure has built-in measures to identify problems and errors during backup processes and remedy with corrective action when possible. However, there are certain situations where your intervention is required.

In this article, I will show you how to enable monitoring for SQL Server managed backup in Azure, and finally enable email notification for any errors that need to be addressed.

Monitoring SQL Server Managed Backup

The SQL Server Managed Backup to Microsoft Azure periodically reviews scheduled backups and attempts to reschedule any failed backups. It polls the storage account periodically to identify breaks in log chains affecting recoverability of the database, and schedules new backups accordingly.

First, you can poll the backup health status by calling managed_backup.fn_get_health_status.

Open SQL Server Management Studio (SSMS) and run the following query. This query returns a table of aggregated error counts for each category that can be used to monitor the health status of SQL Server Managed Backup to Microsoft Azure.

FROM managed_backup.fn_get_health_status(NULL, NULL)

How To Monitor SQL Server Automated Backup in Microsoft AzureStorage #Azure #SQLServer 2

These aggregated counts can be used to monitor system health. For example, if the number_ of_retention_loops column is 0 in 30 minutes, it is possible that retention management is taking long time or even not working correctly. Non-zero error columns may indicate problems and Extended Events logs should be checked to discover the problem.

Next, you can call managed_backup.sp_get_backup_diagnostics stored procedure to find the details of the error and start investigating.

Open SQL Server Management Studio (SSMS) and run the following query. The following example returns all the backup events logged for the past 30 minutes.

Use msdb  
EXEC managed_backup.sp_get_backup_diagnostics


How To Monitor SQL Server Automated Backup in Microsoft AzureStorage #Azure #SQLServer 3

This was the manual monitoring approach.

Enabling Email Notification for SQL Backup Health

Another option is to automate the monitoring of SQL Server Managed Backup by taking advantage of the built-in Database Mail feature for notifications.

SQL Server Managed Backup to Microsoft Azure includes a notification mechanism that is based on SQL Server policy based management policies. Now take the following steps:

  1. You need to configure Database Mail in SQL Server, you can use the steps described here to enable Database Mail.
  2. Set database as the Mail System for SQL Server Alert System: In SQL Server Management Studio (SSMS), right click on SQL Server Agent, select Alert System, check the Enable mail profile box, Select Database Mail as the Mail System, and select the Mail profile that you created in Step 1.
  3. Verify that the SMTP port is allowed both through the local VM firewall and the Network Security Group (NSG) for the VM in Azure.
  4. You need to set the value for the specified Smart Admin system parameter by calling managed_backup.sp_set_parameter. Run the following query in SSMS query window and provide the e-mail address. The following example enables email notifications for errors and warnings only and sets the email ID to use to send the notifications to. This creates a SQL Server Agent job that is used to gather health status and send notifications when there is an error or an issue with SQL backups.
    Use msdb  
    EXEC managed_backup.sp_set_parameter @parameter_name = 'SSMBackup2WANotificationEmailIds', @parameter_value = '<>'
  5. Yon can run the following query to check if Backup is enabled and set to True, and the email ID specified for notifications.
    Use msdb  
    SELECT * FROM managed_backup.fn_get_parameter (NULL)
  6. The last step is to test that you are receiving notifications when your backup is not in healthy state. To simulate this scenario, you can delete few backup files from your Microsoft Azure Storage container, and then wait for 15 minutes and see if you get any email notification. In my example, I deleted few backup files and received the following email.How To Monitor SQL Server Automated Backup in Microsoft AzureStorage #Azure #SQLServer 4

Hope this article was useful to you and happy monitoring day!

Thank you for reading my blog.

If you have any questions or feedback, please leave a comment.

-Charbel Nemnom-




Speaking at HPE Customer Innovation Center in Geneva About Microsoft AzureStack #HPEAzureStack #HPEMSFT #HPECIC @itnetX_CH @HPE_CH @Microsoft_CH

Happy SysAdmin Day With Altaro VMBackup HyperV VMware @AltaroSoftware


Let me know what you think, or ask a question...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Stay in Touch

Never miss out on your favorite posts and our latest announcements!

The content of this website is copyrighted from being plagiarized!

You can copy from the 'Code Blocks' in 'Black' by selecting the Code.

Please send your feedback to the author using this form for any 'Code' you like.

Thank you for visiting!