Tracking The Progress Of A Database Backup Or Restore In SQL Server

Tracking the progress of a database backup or restore can typically be performed, to some degree, within the GUI of SQL Management Studio by the user who is actually performing the backup/restore.  Though the progress indicator in Management Studio is mostly reliable, there are times when another user on a team may perform a backup or restore and, when this is the case, it can be difficult to determine the overall progress without the use of 3rd party software.

I recently ran into this scenario as one of the other Database Administrators on my team kicked off a restore of a large lab database before leaving for the day.  After about an hour and a half I began to question whether there was an issue with the restore. Navigating to the database within SQL Management Studio showed that the database was still in the process of restoring, though the time it was taking seemed to exceed my expectations.

restore_progress_gui

Fortunately, Microsoft has provided a couple useful Dynamics Management Views (DMVs) which, with a little modification, can make querying this information relatively easy.

The script below queries the sys.dm_exec_sql_text and sys.dm_exec_requests management views to provide useful information regarding any active backup or restore processes.

Though this information can be captured by simply querying the sys.dm_exec_requests DMV and adding a WHERE clause to look for 'RESTORE DATABASE' and 'BACKUP DATABASE' making some changes to the way the data is presented will allow for easier interpretation of the data.

In the script above I am using the CONVERT function to provide an easier view of the relevant data.

The screenshot below shows that two databases are currently in the process of being restored.

restore_progress_1

Included in the output is the Session ID (spid), command being executed, percentage complete, ETA Completion Time, Elapsed time in minutes, ETA (min), ETA (hours) and an additional column which includes the SQL script being executed to perform the backup or restore.

The ETA metrics will constantly adjust based on the overall progress of the database restore.  Though this is an estimation, I have found that it is close enough to gauge an approximate time frame for when the process will be complete.