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.

Tail log backups<br />

Chapter 1: Basics of <strong>Backup</strong> <strong>and</strong> <strong>Restore</strong><br />

In the event of a failure affecting a database operating in FULL or BULK_LOGGED<br />

recovery model, the first action after the failure should be to perform what is known as<br />

a tail log backup of the live transaction log, which captures the remaining contents<br />

of this file. In fact, a subsequent RESTORE operation may otherwise fail, unless the<br />

comm<strong>and</strong> includes WITH REPLACE, indicating that the existing database should be<br />

overwritten, or WITH STOPAT, indicating that there is a specific point at which we wish<br />

to stop the restore operation.<br />

If a database is corrupted in some way, but is still online <strong>and</strong> we wish to restore over that<br />

database, then performing a tail log backup with BACKUP LOG…WITH NORECOVERY, will<br />

capture the remaining contents of the live log file <strong>and</strong> put the database into a restoring<br />

state, so that no further transactions against that database will succeed, <strong>and</strong> we can begin<br />

the restore operation.<br />

This sort of tail log backup, as well as normal log backups, require the database to be<br />

online (I believe, so that information regarding the log backup can be stamped into the<br />

database header). If the database is offline, <strong>and</strong> an attempt to bring it back online fails,<br />

perhaps because a data file is unavailable, then a tail log backup WITH NORECOVERY, as<br />

well as any normal log backups, will fail. However, it may still be possible to perform a<br />

tail log backup, but using the NO_TRUNCATE option instead, BACKUP LOG…WITH NO_<br />

TRUNCATE. This operation backs up the log file without truncating it <strong>and</strong> doesn't require<br />

the database to be online.<br />

Of course, any sort of tail log backup will only be possible if the log file is still accessible<br />

<strong>and</strong> undamaged but, assuming this is the case, it should be possible to restore right up<br />

to the time of the last transaction committed <strong>and</strong> written to the log file, before the<br />

failure occurred.<br />

Finally, there is a special case where a tail log backup may not succeed, <strong>and</strong> that is if<br />

there are any minimally logged transactions, recorded while a database was operating in<br />

BULK_LOGGED recovery model, in the live transaction log, <strong>and</strong> a data file is unavailable<br />

34

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

Saved successfully!

Ooh no, something went wrong!