I have been doing quite some backup/restore operations during recent upgrading and migration projects. The sys.dm_exec_requests DMV contains one row for every running command on a SQL Server instance. Two interesting columns (estimated_completion_time, percent_complete) help you answering the "when" and "how much longer" questions.
The SELECT statement below will give you a time estimation for every running "BACKUP DATABASE" or "RESTORE DATABASE" statement. Play around with the WHERE clause to monitor other long running operations.
/* Created by free online sql formatter */
SELECT command, 'EstimatedEndTime' = Dateadd(ms,estimated_completion_time,Getdate()),
'EstimatedSecondsToEnd' = estimated_completion_time / 1000,
'EstimatedMinutesToEnd' = estimated_completion_time / 1000 / 60,
'BackupStartTime' = start_time,
'PercentComplete' = percent_complete
FROM sys.dm_exec_requests
WHERE command IN ('BACKUP DATABASE','RESTORE DATABASE')
1 comment:
your 'backupstarttime' column isn't really given the correct name if it concerns a restore op ;)
Post a Comment