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

Once you do this, your database will be back online <strong>and</strong> recovered up to the point of the<br />

failure! This is a huge time saver since restoring all of the files could take quite a long<br />

time. Having to restore only the data file that was affected by the crash will cut your<br />

recovery time down significantly.<br />

However, there are a few caveats attached to this technique, which we'll discuss as we<br />

walk through a demo. Specifically, we're going to use <strong>SQL</strong> <strong>Backup</strong> scripts (these can<br />

easily be adapted into native T-<strong>SQL</strong> scripts) to show how we might restore just a single<br />

damaged, or otherwise unusable, secondary data file for our DatabaseForFile-<br />

<strong>Backup</strong>s_SB database, without having to restore the primary data file.<br />

Note that if the primary data file went down, we'd have to restore the whole database,<br />

rather than just the primary data file. However, with Enterprise Edition <strong>SQL</strong> <strong>Server</strong>, it<br />

would be possible to get the database back up <strong>and</strong> running by restoring only the primary<br />

data file, followed subsequently by the other data files. We'll discuss that in more detail in<br />

the next section.<br />

This example is going to use our DatabaseForFile<strong>Backup</strong>s_SB database to restore<br />

from a single disk / single file failure, using <strong>SQL</strong> <strong>Backup</strong> T-<strong>SQL</strong> scripts. A script<br />

demonstrating the same process using native T-<strong>SQL</strong> is available with the code<br />

download for this book.<br />

If you recall, for this database we have Table_DF1, stored in the primary data file<br />

(DatabaseForFile<strong>Backup</strong>s_SB.mdf) in the PRIMARY filegroup, <strong>and</strong> Table_DF2,<br />

stored in the secondary data file (DatabaseForFile<strong>Backup</strong>s_SB_Data2.ndf) in the<br />

SECONDARY filegroup. Our first data load (one row into each table) was captured in full<br />

file backups for each filegroup. We then captured a first transaction log backup. Our<br />

second data load (an additional row into each table) was captured in differential file<br />

backups for each filegroup. Finally, we took a second transaction log backup.<br />

Let's perform a third data load, inserting one new row into Table_DF2.<br />

330

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

Saved successfully!

Ooh no, something went wrong!