MSSQL Online File Restore script

Source: Internet
Author: User
Tags filegroup

Online file Restore: If the larger MSSQL database is damaged only by concentrating on one of the files or filegroups, using the online file restore technology,
Just rebuilding a broken data file or filegroup can save a lot of time.
The following is a test script (assuming a corrupted file is Trn01):

--FirstRestore corrupted file Trn01 (before you perform this step, you must obtain exclusive access to the database):RESTORE DATABASE [AdventureWorks] FILE=N'Trn01'  from DISK=N'D:\BACKUP_TEST\AD_FULL. BAK'  withNorecovery,stats=Ten--If it is not an Enterprise Edition, error message 3159 prompts you to use BACKUP LOG with NORECOVERY to back up the tail log, which means that you can only restore files offline.
--BACKUP LOG [AdventureWorks] to DISK =n ' D:\BACKUP_TEST\Log_BACK_TAIL. TRN ' with norecovery,compression,stats=10 --in other words, if it is an Enterprise Edition, you can release exclusive access at this point when execution is complete. (If you change to Single_user mode, you can now change to multi_user release access.)--However, the filegroup trn that the Trn01 belongs to cannot be accessed, and the contents of the database outside the TRN filegroup can be accessed. --If you try to access a table in Trn01, the following error message appears:--msg 8653, Level 16, State 1, line 2nd--The query processor cannot generate a schedule for a table or view "* * *" because the table resides in a filegroup that is not in the online state. --backup file offline point in time log:BACKUP LOG [AdventureWorks] to DISK =N'D:\BACKUP_TEST\Log_BACK_TAIL. TRN' withCopy_only,compression,stats=Ten--Restore the log in turn:RESTORE LOG [AdventureWorks] from DISK=N'D:\BACKUP_TEST\LOG_BACK_1.TRN' withNorecovery,stats=TenRESTORE LOG [AdventureWorks] from DISK=N'D:\BACKUP_TEST\LOG_BACK_2.TRN' withNorecovery,stats=Ten--to restore a file offline point in time log:RESTORE LOG [AdventureWorks] from DISK=N'D:\BACKUP_TEST\Log_BACK_TAIL. TRN' withRecovery,stats=Ten

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.