Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Use common table expressions to simplify your updates in SQL ServerWatch Me (and 23 Others!) During 24 Hours of PASS: Summit Preview »
    comments

    Frequently you will be asked how much longer a restore will take because someone needs to do something with that specific database that is restoring right now

    Of course we all know that the RESTORE DATABASE command has the STATS n option, this will give you the percentage completed. This is nice but it doesn't tell you when it will complete and if someone else started the restore how will you know how long it will take in that case?

    Fear not, here is a query that will tell you exactly how long

    1. SELECT 
    2.     d.PERCENT_COMPLETE AS [%Complete],
    3.     d.TOTAL_ELAPSED_TIME/60000 AS ElapsedTimeMin,
    4.     d.ESTIMATED_COMPLETION_TIME/60000   AS TimeRemainingMin,
    5.     d.TOTAL_ELAPSED_TIME*0.00000024 AS ElapsedTimeHours,
    6.     d.ESTIMATED_COMPLETION_TIME*0.00000024  AS TimeRemainingHours,
    7.     s.text AS Command
    8. FROM    sys.dm_exec_requests d
    9. CROSS APPLY sys.dm_exec_sql_text(d.sql_handle)as s
    10. WHERE  d.COMMAND LIKE 'RESTORE DATABASE%'
    11. ORDER   BY 2 desc, 3 DESC

    Here is the output for a fairly large database restore that I started last night

    %Complete ElapsedTimeMin TimeRemainingMin ElapsedTimeHours TimeRemainingHours Command
    78.6186 766 208 11.03301576 2.99693760 RESTORE database SomeDB

    As you can see the query returns elapsed time both in hours and minutes, time remaining both in hours and minutes and also the percentage complete

    Hopefully this will help you with those nagging types.......

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    1743 views
    Instapaper

    11 comments

    Comment from: calin [Visitor]
    calin I blogged about this a while ago - next step is to show for multiple backups and restores, going at the same time:-).
    Also, because your exposure is so much larger than mine, can you tell people about "Perform Volume Maintenance Tasks"? and how the SQL Server should be assigned to that policy? Otherwise it will take forever for the backup to complete.
    09/02/11 @ 07:48
    Comment from: calin [Visitor]
    calin i'm not sure what i said, but it's the restore that will take much less:-)
    09/02/11 @ 07:50
    Arthur Nice, did not know sys.dm_exec_requests has ESTIMATED_COMPLETION_TIME of a backup restore.

    My suggestion to Microsoft is to include this calculation into the status message showing the percentage complete.

    I guess it better be rounded to two digits or even hours/minutes.

    Thank you Denis!
    09/02/11 @ 07:59
    Comment from: Dattatrey Sindol (Datta) [Visitor] Email · http://dattatreysindol.blogspot.com/
    Dattatrey Sindol (Datta) Good one.
    Didn't know this before.
    09/09/11 @ 03:08
    Comment from: David Forck (thirster42) [Member]
    I
    like
    your
    blog
    Denis
    09/09/11 @ 08:52
    Comment from: Amelia @ IT Management [Visitor]
    Amelia @ IT Management I didn't know about this before. This is helpful because I'm one of those "nagging types."

    I like to know when a restore completes so that I can wrap my schedule around it. It's just pure agony not knowing.
    09/09/11 @ 18:37
    Tim Laqua Try estimating the exact time of completion since your business users don't have to do the math ;-)

    http://timlaqua.com/2009/09/determining-when-restore-database-command-will-complete-sql-server-2008/
    09/21/11 @ 09:01
    Comment from: Amelia @ IT Management [Visitor] · http://www.invgate.com
    Amelia @ IT Management I just tried this out and it works! Now I don't have to nag while waiting.

    I gave this to a friend and she thanked me with a box of chocolates. Thank you very much, SQLDenis.
    10/06/11 @ 17:52
    Comment from: Naomi Nosonovsky [Member]
    Naomi Nosonovsky I think you should have sent them to Denis :)
    10/07/11 @ 11:36
    Comment from: Naomi Nosonovsky [Member]
    Naomi Nosonovsky BTW, is there a way to estimate how long the backup will take?
    11/24/11 @ 09:58
    Comment from: SQLDenis [Member] Email
    SQLDenis Change restore database to backup database. See here: How long will the database backup take?
    11/24/11 @ 10:24

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)