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 7: Differential <strong>Backup</strong> <strong>and</strong> <strong>Restore</strong><br />

Native T-<strong>SQL</strong> differential restore<br />

We're now going to perform a second differential restore, this time using T-<strong>SQL</strong><br />

scripts. While we could perform this operation in a single script, we're going to split<br />

it out into two scripts so that we can see, more clearly than we could during the GUI<br />

restore, the exact steps of the process. Once again, our restore will overwrite the existing<br />

DatabaseForDiff<strong>Backup</strong>s database. The first step will restore the base backup,<br />

containing 100,000 rows, <strong>and</strong> leave the database in a "restoring" state. The second step<br />

will restore the second differential backup file (_Diff_Native_2.bak), containing all<br />

the rows changed or added since the base backup (10,000 rows from the second data<br />

load <strong>and</strong> another 100,000 from the third), <strong>and</strong> then recover the database, returning it<br />

to a usable state.<br />

Without further ado, let's restore the base backup file, using the script in Listing 7-8.<br />

USE [master]<br />

GO<br />

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

FROM DISK = N'C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter7\DatabaseForDiff<strong>Backup</strong>s_Full_Native.bak'<br />

WITH NORECOVERY, STATS = 10<br />

GO<br />

Listing 7-8: Base full database backup restore.<br />

Notice the WITH NORECOVERY argument, meaning that we wish to leave the database in<br />

a restoring state, ready to receive further backup files. Also note that we did not specify<br />

REPLACE since it is not needed here, since DatabaseForDiff<strong>Backup</strong>s is a SIMPLE<br />

recovery model database.<br />

Having executed the script, refresh your object explorer window <strong>and</strong> you should see that<br />

the DatabaseForDiff<strong>Backup</strong>s database now displays a Restoring… message, as shown<br />

in Figure 7-9.<br />

227

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

Saved successfully!

Ooh no, something went wrong!