Total Pageviews

Thursday, November 8, 2012

SQL Backup/Restore Percentage and Time Remaining

When you perform a restore from the GUI with SQL Server, there is a status indicator at the bottom right that tells the percentage complete.  However, when you restore from T-SQL, there is not one by default.  That information is actually stored in the sys.dm_exec_requests as well as estimated time remaining, stored in milliseconds.    Here is an example query that shows the percentage complete, as well as an estimated time remaining.


USE MASTER
GO
SELECT percent_complete,start_time,command,b.name AS DatabaseName,
      DATEADD(ms,estimated_completion_time,GETDATE()) AS RemainTime,
      (estimated_completion_time/1000/60) AS MinutesToFinish
FROM sys.dm_exec_requests a
      INNER JOIN sys.databases b
      ON a.database_id = b.database_id
WHERE command like '%restore%' or command like '%Backup%' AND estimated_completion_time > 0


Example:


No comments:

Post a Comment