T-SQL Script to check the database backup and restore progress and estimated completion time

 Script 1: 

select 

d.name as [Database Name],

Percent_complete, 

dateadd(second,estimated_completion_time/1000, 

getdate()) as EstimatedCompletionTime, Getdate() as Current_Time_now, 

CAST((datediff(minute, start_time, getdate())) as varchar(50)) +'  ' + 'Minutes' as CMD_Running_From, 

CAST((estimated_completion_time/1000/60) as varchar(50)) +'  ' + 'Minutes'  as Will_Complete_in,

start_time as CMD_Start_Time, 

command As Running_Command

from sys.dm_exec_requests req

inner join sys.sysdatabases d on d.dbid = req.database_id

where 

req.command in ('RESTORE DATABASE', 'BACKUP DATABASE', 'RESTORE LOG', 'BACKUP LOG')


Script 2:


select 

d.name,

percent_complete, dateadd(second,estimated_completion_time/1000, getdate()) as EstimatedCompletionTime, Getdate() as now, 

datediff(minute, start_time, getdate()) as running, estimated_completion_time/1000/60 as togo,

start_time, command 

from sys.dm_exec_requests req

inner join sys.sysdatabases d on d.dbid = req.database_id

where 

req.command in ('RESTORE DATABASE', 'BACKUP DATABASE', 'RESTORE LOG', 'BACKUP LOG')

Comments

Popular posts from this blog

SQL Server DBA scripts for day-to-day tasks

SQL Server Dynamic management views (DMV's)

A brief comparison of Microsoft SQL Server versions from SQL Server 2012 to SQL Server 2022