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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: File <strong>and</strong> Filegroup <strong>Backup</strong> <strong>and</strong> <strong>Restore</strong><br />

The next step is to restore the second transaction log backup (_TLOG2), as shown in<br />

Listing 9-21. When it comes to restoring the transaction log backup files, we need to<br />

specify NORECOVERY on all of them except the last. The last group of log backup files<br />

we are restoring (represented by only a single log backup in this example!) may be<br />

processing data for all of the data files <strong>and</strong>, if we do not specify NORECOVERY, we can<br />

end up putting the database in a usable state for the user, but unable to apply the last<br />

of the log backup files.<br />

USE master<br />

GO<br />

RESTORE DATABASE [DatabaseForFile<strong>Backup</strong>s]<br />

FROM DISK = N'C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter9\DatabaseForFile<strong>Backup</strong>s_TLOG2.trn'<br />

WITH NORECOVERY<br />

GO<br />

Listing 9-21: <strong>Restore</strong> the second log backup.<br />

Finally, we need to apply the tail log backup, where we know our third data load is<br />

captured, <strong>and</strong> recover the database.<br />

RESTORE DATABASE [DatabaseForFile<strong>Backup</strong>s]<br />

FROM DISK = N'C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter9\DatabaseForFile<strong>Backup</strong>s_TLOG_TAIL.trn'<br />

WITH RECOVERY<br />

GO<br />

Listing 9-22: <strong>Restore</strong> the tail log backup <strong>and</strong> recover the database.<br />

A simple query of the restored database will confirm that we've restored the database,<br />

with all the rows intact.<br />

USE [DatabaseForFile<strong>Backup</strong>s]<br />

GO<br />

SELECT * FROM Table_DF1<br />

SELECT * FROM Table_DF2<br />

325

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

Saved successfully!

Ooh no, something went wrong!