Determine or Estimated time (ETA) of Backup & Restoration
73 views 04:39 0 Comments4 December 2019
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.
/*Author: Chris YatesOriginal link: http://www.sqlservercentral.com/blogs/the-sql-professor/2017/01/26/backuprestorewhats-my-status/*/-- By checking only for the restore and backup command lines you will be able to quickly identify your session id-- and get an approximate ETA and percentage complete. You can tinker of course with the estimations-- if you’d like or pull back more fields. This is just a simple technique in utilizing a helpful DMV to provide info quickly.SELECT r.session_id AS'Session ID', r.command AS'Command', r.start_time AS'Start Time', r.status AS'Status',CONVERT(NUMERIC(6, 2), r.percent_complete) 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 Minutes',CONVERT(NUMERIC(10, 2), r.total_elapsed_time /1000.0/60.0/60.0) AS'Elapsed Hours',CONVERT(NUMERIC(10, 2), r.estimated_completion_time /1000.0/60.0) AS'ETA Minutes',CONVERT(NUMERIC(10, 2), r.estimated_completion_time /1000.0/60.0/60.0) AS'ETA Hours',CONVERT(VARCHAR(1000), (SELECTSUBSTRING(TEXT, r.statement_start_offset /2, CASEWHEN r.statement_end_offset =-1THEN1000ELSE (r.statement_end_offset - r.statement_start_offset) /2END)FROM sys.dm_exec_sql_text(sql_handle) )) AS'T-SQL Statement'FROM sys.dm_exec_requests rWHERE command IN ('RESTORE DATABASE','BACKUP LOG','BACKUP DATABASE');