Skip to content

Instantly share code, notes, and snippets.

@petesql
Last active August 26, 2022 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petesql/2385ca22d7ee211b045904e34ea082c9 to your computer and use it in GitHub Desktop.
Save petesql/2385ca22d7ee211b045904e34ea082c9 to your computer and use it in GitHub Desktop.
-- Get estimated backup & restore time
SELECT
r.session_id,
r.user_id,
r.start_time,
dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time,
r.percent_complete,
r.command,
d.name,
s.text AS full_command_text
FROM sys.dm_exec_requests r
JOIN sys.databases d ON r.database_id = d.database_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) s
CROSS APPLY sys.dm_exec_input_buffer(r.session_id, r.request_id) AS ib
WHERE 1=1
AND r.command IN (
'RESTORE DATABASE',
'BACKUP DATABASE',
'RESTORE LOG',
'BACKUP LOG',
'DbccSpaceReclaim',
'DbccFilesCompact');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment