MSSQL 2012 Log Restore

Source: Internet
Author: User
Tags mssql

Log Restore conditions

--Condition One: Check the recovery model of the database: Full
--condition Two: There is a last full backup
--condition Three: A full backup does not force truncation of the log
--condition four: log backup after a failure occurred

CREATE TABLE [dbo]. [TB] (
Name [varchar] (Ten) NULL,
Course [varchar] (Ten) NULL,
Score [INT] Null
) on [PRIMARY]

Insert into TB (name, course, score) VALUES (' 31 ', ' language ', ' 80 '), (' Zhang San ', ' language ', ' 80 '), (' Zhang 32 ', ' math ', 90 '), (' 33 ', ' English ', 70)

---full backup:

go
backup Database Test
    to disk= ' D:\Backup\TEST_FullDB_20141103.bak '
    With  init


---Analog failure time, time before and after recording
Use Test
GO
Select GETDATE ()--2014-11-03 21:39:30.323
UPdate TB
SET fraction = 150--120
Select GETDATE ()--2014-11-03 21:39:30.323

---No forced truncation of log backups after a failure
backup Log Test
    to disk= ' D:\Backup\TEST_Log_20141103_2.trn '
    With  no_truncate , init


---restore to another database . NORECOVERY mode (because the test environment is only one DB instance, the path should be indicated)
use [master]
restore DATABASE [test_new]
from  DISK = N ' D:\Backup\TEST_FullDB _20141103.bak '
with FILE = 1,
move n ' Test ' to N ' d:\ Backup\test.ndf ',  
move n ' test_log ' to N ' D:\Backup\ Test.ldf ',  

----Log restore is performed repeatedly until the real point in time, the purpose of using standby is to worry about the point in time selection is inaccurate enough,

can also resume log backups
use [master]
restore LOG [test_new]
    WITH  FILE = 1,  
     standby = N ' D:\Backup\ROLLBACK_UNDO_TEST_New.BAK ',  
    stopat = N ' 2014-11-03 21:39:30.323 '


-----View Results
Use Test_new
--Use TEST
Select * from DBO.TB (NOLOCK)
--2014-11-03 21:32:19.070

---Last updated ....

MSSQL 2012 Log Restore

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.