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 />

DatabaseForLog<strong>Backup</strong>s_<strong>Restore</strong>Copy database, which is a FULL recovery model<br />

database, <strong>and</strong> we have not backed up the tail of the log, so we would lose any transactions<br />

that were not previously captured in a backup.<br />

This is a very useful warning message to get in cases where we needed to perform crash<br />

recovery <strong>and</strong> had, in fact, forgotten to do a tail log backup. In such cases, we could start<br />

the restore process with the tail log backup, as shown in Listing 6-6, <strong>and</strong> then proceed.<br />

USE master<br />

GO<br />

BACKUP LOG DatabaseForLog<strong>Backup</strong>s_<strong>Restore</strong>Copy<br />

TO DISK = 'D:\<strong>SQL</strong><strong>Backup</strong>s\Chapter5\DatabaseForLog<strong>Backup</strong>s_<strong>Restore</strong>Copy_log_tail.trn'<br />

WITH NORECOVERY<br />

Listing 6-6: Perform a tail log backup.<br />

In cases where we're certain that our restore operation does not require a tail log backup,<br />

we can use WITH REPLACE or WITH STOPAT. In this case, the error can be removed,<br />

without backing up the tail of the log, by adding the WITH REPLACE clause to Listing 6-5.<br />

Let's take a look at a second example failure. Examine the script in Listing 6-7 <strong>and</strong> see if<br />

you can spot the problem.<br />

--STEP 1: <strong>Restore</strong> the log backup<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 />

STATS = 10, REPLACE<br />

GO<br />

201

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

Saved successfully!

Ooh no, something went wrong!