Created
January 16, 2015 23:53
-
-
Save jcefoli/bb880c5588b853338b27 to your computer and use it in GitHub Desktop.
[MSSQL] Checks Status of a DB Restore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @sql_text char(255); | |
declare @total_time_so_far int; | |
declare @total_percent float; | |
declare @seconds_per_percent float; | |
declare @total_time time; | |
declare @time_left time; | |
SELECT @sql_text = sqltext.TEXT, | |
@total_time_so_far = req.total_elapsed_time, | |
@total_percent = req.percent_complete | |
FROM sys.dm_exec_requests req | |
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext where | |
sqltext.TEXT like '%restore%' and sqltext.TEXT not like '%select sqltext.TEXT%' | |
SELECT @seconds_per_percent = (@total_time_so_far / 1000) / @total_percent | |
SELECT @total_time = CONVERT(TIME, DATEADD(SECOND, @seconds_per_percent * 100,0), 108) | |
SELECT @time_left = CONVERT(TIME, DATEADD(second, @seconds_per_percent * (100-@total_percent),0), 108) | |
SELECT @total_time_so_far as 'Total Time So Far (in ms)', @total_percent as '% Completed', @seconds_per_percent as 'Seconds per %', @total_time as 'Estimated total time', @time_left as 'Estimated remaining time' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment