As a DBA you may face a few common questions whenever someone accidentally deleted some database objects or the whole database.
“How long-time SQL Server will take to complete the database Backup or Restore? Yes DBA speaks out!! move your jaw and tell something!!”
Performing database refresh activity, database migration activity, or any adhoc activity where DBA is handling a huge size database need to answer higher authorities or managers about the estimated time amount to do the activity.
In this post, we will try a simple script to get the estimated amount of time that SQL Server is going to take to complete database Backup or Restore.
This script can be used to find the estimated time of backup and restore that is on progress in your SQL server. This script is applicable for SQL Server 2005 and above. While your backup and restoration activity is going on, execute the below script.
AS [Percent Complete],CONVERT(VARCHAR(20),DATEADD(ms,r.estimated_completion_time,GetDate()),20) AS [ETA Completion Time],
CONVERT(NUMERIC(10,2),r.total_elapsed_time/1000.0/60.0) AS [Elapsed Min],
CONVERT(NUMERIC(10,2),r.estimated_completion_time/1000.0/60.0) AS [ETA Min],
CONVERT(NUMERIC(10,2),r.estimated_completion_time/1000.0/60.0/60.0) AS [ETA Hours],
CASE WHEN r.statement_end_offset = -1 THEN 1000 ELSE (r.statement_end_offset-r.statement_start_offset)/2 END)
FROM sys.dm_exec_sql_text(sql_handle))) AS [SQL]
FROM sys.dm_exec_requests r WHERE command IN ('RESTORE DATABASE','BACKUP LOG', 'BACKUP Database')