Home SQL ServerDBADatabase How to Monitor SQL Server Backup and Restore Progress with T-SQL

How to Monitor SQL Server Backup and Restore Progress with T-SQL

by Ernie
1 minutes read
A+A-
Reset

Monitoring the progress of SQL Server backup and restore operations is essential to ensuring the availability and reliability of critical data. Using the sys.dm_exec_requests dynamic management view and the sys.dm_exec_sql_text function, database administrators can retrieve information about backup and restore operations currently running on the server, such as the percentage complete, the estimated completion time, and the elapsed time. By monitoring backup and restore progress using T-SQL scripts that join these views with the CROSS APPLY operator, database administrators can proactively identify any issues and take appropriate action to prevent data loss.

T-Sql
				
					--Script to monitor the progress of a sql server backup or restore activity
SELECT session_id as spid
	, command
	, a.text AS query
	, start_time
	, percent_complete
	, dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time
FROM sys.dm_exec_requests r 
   CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a 
WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')
--this where condition is filtering for both bacup and restore activity. just alter this line accordingly.
				
			
Source: mssqltips

You may also like

Leave a Comment

HOWSDATA @2023 · All lefts reserved

How's Data
Unlocking the world of data, one byte at a time

This website uses cookies to enhance your experience, but you may choose to opt-out if you prefer. For more information on this site and its content usage, please refer to the About page. Accept Read More