You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This article teaches you how to monitor backup activity for [Azure SQL Managed Instance](sql-managed-instance-paas-overview.md) by either querying the `msdb` database or by configuring extended event (XEvent) sessions.
18
20
19
21
## Overview
20
22
21
-
Azure SQL Managed Instance stores backup information in the [msdb database](backup-transparency.md) and also emits events (also known as [Extended Events or XEvents](../database/xevent-db-diff-from-svr.md)) during backup activity for the purpose of reporting. Configure an XEvent session to track information such as backup status, backup type, size, time, and location within the `msdb` database. This information can be integrated with backup monitoring software and also used for the purpose of Enterprise Audit.
23
+
Azure SQL Managed Instance stores backup information in the [msdb database](backup-transparency.md) and also emits events (also known as [Extended Events or XEvents](../database/xevent-db-diff-from-svr.md)) during backup activity, which can be used for reporting. Configure an XEvent session to track information such as backup status, backup type, size, time, and location within the `msdb` database. This information can be integrated with backup monitoring software and also used for Enterprise Audit.
22
24
23
-
Enterprise Audits may require proof of successful backups, time of backup, and duration of the backup.
25
+
Enterprise Audits might require proof of successful backups, time of backup, and duration of the backup.
24
26
25
27
## Query msdb database
26
28
27
-
To view backup activity, run the following query from user-defined database:
29
+
To view backup activity, run the following query from user-defined database:
28
30
29
31
```sql
30
-
SELECT TOP (30) bs.machine_name, bs.server_name, DB_NAME(DB_ID(bs.database_name)) AS [Database Name], bs.recovery_model,
31
-
CONVERT (BIGINT, bs.backup_size/1048576 ) AS [Uncompressed Backup Size (MB)],
32
-
CONVERT (BIGINT, bs.compressed_backup_size/1048576 ) AS [Compressed Backup Size (MB)],
DB_NAME(DB_ID(bs.database_name)) AS [Database Name],
34
+
CONVERT (BIGINT, bs.backup_size/1048576) AS [Uncompressed Backup Size (MB)],
35
+
CONVERT (BIGINT, bs.compressed_backup_size/1048576) AS [Compressed Backup Size (MB)],
36
+
CONVERT (NUMERIC (20, 2),
37
+
CASE
38
+
WHEN bs.compressed_backup_size>0
39
+
THEN CONVERT (FLOAT, bs.backup_size) /CONVERT (FLOAT, bs.compressed_backup_size)
40
+
ELSE NULL
41
+
END
42
+
) AS [Compression Ratio],
43
+
bs.is_copy_only,
44
+
-- bs.user_name, -- Applicable only for user-initiated COPY ONLY backups.
45
+
bs.has_backup_checksums,
46
+
DATEDIFF(SECOND, bs.backup_start_date, bs.backup_finish_date) AS [Backup Elapsed Time (sec)],
47
+
bs.backup_finish_dateAS [Backup Finish Date],
48
+
bmf.physical_block_size
37
49
FROMmsdb.dbo.backupset AS bs WITH (NOLOCK)
38
-
INNER JOINmsdb.dbo.backupmediafamily AS bmf WITH (NOLOCK)
39
-
ONbs.media_set_id=bmf.media_set_id
40
-
WHEREDB_ID(bs.database_name)=DB_ID()
41
-
AND bs.[type] ='D'
42
-
ORDER BYbs.backup_finish_dateDESC OPTION (RECOMPILE);
43
-
50
+
INNER JOINmsdb.dbo.backupmediafamily AS bmf WITH (NOLOCK)
51
+
ONbs.media_set_id=bmf.media_set_id
52
+
WHERE bs.[type]='D'
53
+
--AND bs.[is_copy_only] = 1 -- If you want to filter out for user initiated COPY ONLY backups.
54
+
ORDER BYbs.backup_finish_dateDESC
55
+
OPTION (RECOMPILE); -- Optimize for ad hoc execution
44
56
```
45
57
46
-
## Configure XEvent session
58
+
> [!NOTE]
59
+
> When querying `msdb` system tables such as `dbo.backupmediaset` or `dbo.backupset`, you see encryption-related fields indicating that backup files aren't encrypted. This status reflects only engine-level encryption. All automatic backups [are encrypted at rest](automated-backups-overview.md#encrypted-backups).
47
60
48
-
Use the extended event `backup_restore_progress_trace` to record the progress of your SQL Managed Instance back up. Modify the XEvent sessions as needed to track the information you're interested in for your business. These T-SQL snippets store the XEvent sessions in the ring buffer, but it's also possible to write to [Azure Blob Storage](../database/xevent-code-event-file.md). XEvent sessions storing data in the ring buffer have a limit of about 1000 messages so should only be used to track recent activity. Additionally, ring buffer data is lost upon failover. As such, for a historical record of backups, write to an event file instead.
61
+
## Configure XEvent session
49
62
50
-
### Simple tracking
63
+
Use the extended event `backup_restore_progress_trace` to record the progress of your SQL Managed Instance back up. Modify the XEvent sessions as needed to track the information you're interested in for your business. These T-SQL snippets store the XEvent sessions in the ring buffer, but it's also possible to write to [Azure Blob Storage](../database/xevent-code-event-file.md). XEvent sessions storing data in the ring buffer have a limit of about 1,000 messages so should only be used to track recent activity. Additionally, ring buffer data is lost upon failover. As such, for a historical record of backups, write to an event file instead.
51
64
52
-
Configure a simple XEvent session to capture simple events about complete full backups. This script collects the name of the database, the total number of bytes processed, and the time the backup completed.
65
+
### Basic tracking
53
66
54
-
Use Transact-SQL (T-SQL) to configure the simple XEvent session:
67
+
Configure a basic XEvent session to capture events about complete full backups. This script collects the name of the database, the total number of bytes processed, and the time the backup completed.
55
68
69
+
Use [!INCLUDE [tsql-md](../../docs/includes/tsql-md.md)] (T-SQL) to configure the basic XEvent session:
56
70
57
71
```sql
58
-
CREATE EVENT SESSION [Simple backup trace] ON SERVER
CREATE EVENT SESSION [Basic backup trace] ON SERVER
73
+
ADD EVENT sqlserver.backup_restore_progress_trace
74
+
(
75
+
WHERE operation_type =0
76
+
AND trace_message LIKE'%100 percent%'
77
+
)
78
+
ADD TARGET package0.ring_buffer WITH (STARTUP_STATE =ON);
64
79
GO
65
-
ALTER EVENT SESSION [Simple backup trace] ON SERVER
80
+
81
+
ALTER EVENT SESSION [Basic backup trace] ON SERVER
66
82
STATE = start;
67
83
```
68
84
69
-
70
-
71
85
### Verbose tracking
72
86
73
-
Configure a verbose XEvent session to track greater details about your backup activity. This script captures start and finish of both full, differential and log backups. Since this script is more verbose, it fills up the ring buffer faster, so entries may recycle faster than with the simple script.
87
+
Configure a verbose XEvent session to track greater details about your backup activity. This script captures start and finish of both full, differential and log backups. Since this script is more verbose, it fills up the ring buffer faster, so entries might recycle faster than with the basic script.
74
88
75
-
Use Transact-SQL (T-SQL) to configure the verbose XEvent session:
89
+
Use T-SQL to configure the verbose XEvent session:
76
90
77
91
```sql
78
-
CREATE EVENT SESSION [Verbose backup trace] ON SERVER
92
+
CREATE EVENT SESSION [Verbose backup trace] ON SERVER
@@ -89,75 +103,70 @@ WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,
89
103
90
104
ALTER EVENT SESSION [Verbose backup trace] ON SERVER
91
105
STATE = start;
92
-
93
106
```
94
107
95
-
## Monitor backup progress
108
+
## Monitor backup progress
96
109
97
-
After the XEvent session is created, you can use Transact-SQL (T-SQL) to query ring buffer results and monitor the progress of the backup. Once the XEvent starts, it collects all backup events so entries are added to the session roughly every 5-10 minutes.
110
+
After the XEvent session is created, you can use T-SQL to query ring buffer results and monitor the progress of the backup. Once the XEvent starts, it collects all backup events so entries are added to the session roughly every 5-10 minutes.
98
111
99
-
### Simple tracking
112
+
### Basic tracking
100
113
101
-
The following Transact-SQL (T-SQL) code queries the simple XEvent session and returns the name of the database, the total number of bytes processed, and the time the backup completed:
114
+
The following T-SQL code queries the basic XEvent session and returns the name of the database, the total number of bytes processed, and the time the backup completed:
102
115
103
-
```sql
116
+
```sql
104
117
WITH
105
-
a AS (SELECT xed = CAST(xet.target_dataAS xml)
106
-
FROMsys.dm_xe_session_targetsAS xet
107
-
JOINsys.dm_xe_sessionsAS xe
108
-
ON (xe.address=xet.event_session_address)
109
-
WHERExe.name='Backup trace'),
110
-
b AS(SELECT
111
-
d.n.value('(@timestamp)[1]', 'datetime2') AS [timestamp],
112
-
ISNULL(db.name, d.n.value('(data[@name="database_name"]/value)[1]', 'varchar(200)')) AS database_name,
113
-
d.n.value('(data[@name="trace_message"]/value)[1]', 'varchar(4000)') AS trace_message
The following screenshot shows an example of the output of the above query:
122
-
123
-

133
+
The following screenshot shows an example of the output of the previous query:
124
134
125
-
In this example, five databases were automatically backed up over the course of 2 hours and 30 minutes, and there are 130 entries in the XEvent session.
135
+
:::image type="content" source="media/backup-activity-monitor/present-xevents-output.png" alt-text="Screenshot of the XEvent output." lightbox="media/backup-activity-monitor/present-xevents-output.png":::
126
136
127
-
### Verbose tracking
137
+
In this example, five databases were automatically backed up over the course of 2 hours and 30 minutes, and there are 130 entries in the XEvent session.
128
138
129
-
The following Transact-SQL (T-SQL) code queries the verbose XEvent session and returns the name of the database, as well as the start and finish of both full, differential and log backups.
139
+
### Verbose tracking
130
140
141
+
The following T-SQL code queries the verbose XEvent session and returns the name of the database, as well as the start and finish of both full, differential and log backups.
131
142
132
143
```sql
133
144
WITH
134
-
a AS (SELECT xed = CAST(xet.target_dataAS xml)
135
-
FROMsys.dm_xe_session_targetsAS xet
136
-
JOINsys.dm_xe_sessionsAS xe
137
-
ON (xe.address=xet.event_session_address)
138
-
WHERExe.name='Verbose backup trace'),
139
-
b AS(SELECT
140
-
d.n.value('(@timestamp)[1]', 'datetime2') AS [timestamp],
141
-
ISNULL(db.name, d.n.value('(data[@name="database_name"]/value)[1]', 'varchar(200)')) AS database_name,
142
-
d.n.value('(data[@name="trace_message"]/value)[1]', 'varchar(4000)') AS trace_message
Once your backup has completed, you can then [restore to a point in time](point-in-time-restore.md) or [configure a long-term retention policy](long-term-backup-retention-configure.md).
168
+
## Related content
162
169
163
-
To learn more, see [automated backups](automated-backups-overview.md).
170
+
-[Restore a database in Azure SQL Managed Instance to a previous point in time](point-in-time-restore.md)
0 commit comments