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 8: Database <strong>Backup</strong> <strong>and</strong> <strong>Restore</strong> with <strong>SQL</strong> <strong>Backup</strong> Pro<br />

Rerun our data verification query, from Listing 8-18 <strong>and</strong> you should see that we now have<br />

the 42 rows restored to MessageTable2.<br />

<strong>Restore</strong> to st<strong>and</strong>by using a <strong>SQL</strong> <strong>Backup</strong> script<br />

Before we move on, it's worth taking a more detailed look at the <strong>SQL</strong> <strong>Backup</strong> T-<strong>SQL</strong><br />

script that we'd use to perform the same point-in-time restore operation.<br />

EXECUTE master..sqlbackup '-<strong>SQL</strong> "RESTORE DATABASE [DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_St<strong>and</strong>by]<br />

FROM DISK = ''C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter8\DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_Full_BASE2.sqb''<br />

WITH NORECOVERY, MOVE ''DatabaseFor<strong>SQL</strong><strong>Backup</strong>s''<br />

TO ''C:\<strong>SQL</strong>Data\DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_St<strong>and</strong>by.mdf'',<br />

MOVE ''DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_log'' TO<br />

''C:\<strong>SQL</strong>Data\DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_St<strong>and</strong>by_log.ldf''"'<br />

EXECUTE master..sqlbackup '-<strong>SQL</strong> "RESTORE LOG [DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_St<strong>and</strong>by]<br />

FROM DISK = ''C:\<strong>SQL</strong><strong>Backup</strong>s\Chapter8\DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_Log_3.sqb''<br />

WITH STANDBY = ''C:\<strong>SQL</strong><strong>Backup</strong>s\Undo_DatabaseFor<strong>SQL</strong><strong>Backup</strong>s_St<strong>and</strong>by.dat'',<br />

STOPAT = ''2011-12-06T10:42:46'', ORPHAN_CHECK"'<br />

Listing 8-19: <strong>Restore</strong> to st<strong>and</strong>by <strong>SQL</strong> <strong>Backup</strong> script.<br />

The first comm<strong>and</strong> restores the base backup file to a new database, using the MOVE<br />

argument to copy the existing data <strong>and</strong> log files to the newly designated files. We<br />

specify NORECOVERY so that the database remains in a restoring state, to receive<br />

further backup files.<br />

The second comm<strong>and</strong> applies the log backup file to this new database. Notice the use of<br />

the WITH STANDBY clause, which indicates the restored state of the new database, <strong>and</strong><br />

associates it with the correct undo file. Also, we use the STOPAT clause, with which you<br />

should be familiar from Chapter 4, to specify the exact point in time to which we wish<br />

to roll forward. Any transactions that were uncommitted at the time will be rolled back<br />

during the restore.<br />

288

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

Saved successfully!

Ooh no, something went wrong!