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

Note that it is recommended, where possible, to take a full database backup <strong>and</strong> start<br />

the log backups, before taking the first file backup (see: http://msdn.microsoft.com/<br />

en-us/library/ms189860.aspx). We'll discuss this in more detail shortly, but note that, in<br />

order to focus purely on the logistics of file backups, we don't follow this advice in<br />

our examples.<br />

Preparing for file backups<br />

Before we get started taking file backups, we need to do the usual preparatory work,<br />

namely choosing an appropriate recovery model for our database, <strong>and</strong> then creating that<br />

database along with some populated sample tables. Since we've been through this process<br />

many times now, I'll only comment on those parts of the scripts that are substantially<br />

different from what has gone before. Please refer back to Chapters 3 <strong>and</strong> 5 if you need<br />

further explanation of any other aspects of these scripts.<br />

Recovery model<br />

Since we've established the need to take log backups, we will need to operate the database<br />

in FULL recovery model. We can also take log backups in the BULK_LOGGED model<br />

but, as discussed in Chapter 1, this model is only suitable for short-term use during bulk<br />

operations. For the long-term operation of databases requiring file backups, we should be<br />

using the FULL recovery model.<br />

Sample database <strong>and</strong> tables plus initial data load<br />

Listing 9-6 shows the script to create a database with both a PRIMARY <strong>and</strong> a SECONDARY<br />

filegroup, <strong>and</strong> one data file in each filegroup. Again, note that I've used the same drive<br />

for each filegroup <strong>and</strong> the log file, purely as a convenience for this demo; in reality, they<br />

would be on three different drives, as demonstrated previously in Listing 9-3.<br />

306

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

Saved successfully!

Ooh no, something went wrong!