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