30.06.2013 Views

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6: Log <strong>Restore</strong>s<br />

restore <strong>and</strong> placed the database in a recovered state, ready for user access (with only ten<br />

rows in each table!); no log backup files can then be applied as part of the current restore<br />

operation. Always specify NORECOVERY if you need to continue further with a log backup<br />

restore operation.<br />

Of course, there are many other possible errors that can arise if you're not fully paying<br />

attention during the restore process, <strong>and</strong> we can't cover them all. However, as one final<br />

example, take a look at Listing 6-8 <strong>and</strong> see if you can spot the problem.<br />

USE [master]<br />

GO<br />

RESTORE DATABASE [DatabaseForLog<strong>Backup</strong>s_<strong>Restore</strong>Copy]<br />

FROM DISK = N'C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter5\DatabaseForLog<strong>Backup</strong>s_Native_Full.bak'<br />

WITH FILE = 1,<br />

MOVE N'DatabaseForLog<strong>Backup</strong>s'<br />

TO N'C:\<strong>SQL</strong>Data\DatabaseForLog<strong>Backup</strong>s_<strong>Restore</strong>Copy.mdf',<br />

MOVE N'DatabaseForLog<strong>Backup</strong>s_log'<br />

TO N'C:\<strong>SQL</strong>Data\DatabaseForLog<strong>Backup</strong>s__<strong>Restore</strong>Copy_1.ldf',<br />

NORECOVERY, STATS = 10, REPLACE<br />

GO<br />

RESTORE LOG [DatabaseForLog<strong>Backup</strong>s]<br />

FROM DISK = N'C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter5\DatabaseForLog<strong>Backup</strong>s_Native_Log_2.trn'<br />

WITH FILE = 1, NORECOVERY, STATS = 10<br />

GO<br />

RESTORE LOG [DatabaseForLog<strong>Backup</strong>s]<br />

FROM DISK = N'C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter5\DatabaseForLog<strong>Backup</strong>s_Native_Log_1.trn'<br />

WITH FILE = 1, RECOVERY, STATS = 10<br />

GO<br />

Listing 6-8: Forcing one more fun failure.<br />

Did you catch the problem before you ran the script? If not, take a look at your output,<br />

examine the error message you get when the first log file restore is attempted. I'm sure<br />

you'll be able to figure out what's wrong in short order!<br />

203

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!