Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Created March 11, 2015 17:32
Show Gist options
  • Select an option

  • Save JohnLBevan/910cc369f465b7a7ced3 to your computer and use it in GitHub Desktop.

Select an option

Save JohnLBevan/910cc369f465b7a7ced3 to your computer and use it in GitHub Desktop.
How long until a restore completes (NB: Script is easily adaptable to work for other running queries too)
SELECT getutcdate() TimeNowUTC
,d.PERCENT_COMPLETE AS [%Complete]
,d.TOTAL_ELAPSED_TIME/60000 AS ElapsedTimeMin
,d.ESTIMATED_COMPLETION_TIME/60000 AS TimeRemainingMin
,d.TOTAL_ELAPSED_TIME*0.00000024 AS ElapsedTimeHours
,d.ESTIMATED_COMPLETION_TIME*0.00000024 AS TimeRemainingHours
,s.text AS Command
FROM sys.dm_exec_requests d
CROSS APPLY sys.dm_exec_sql_text(d.sql_handle) s
WHERE d.COMMAND LIKE 'RESTORE DATABASE%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment