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

<strong>SQL</strong> <strong>Backup</strong> Pro full backup using T-<strong>SQL</strong><br />

We're now going to perform a second full backup our DatabaseFor<strong>SQL</strong><strong>Backup</strong>s<br />

database, but this time using a <strong>SQL</strong> <strong>Backup</strong> T-<strong>SQL</strong> script, which will look similar to the<br />

one we saw on the Script tab of Step 5 of the GUI wizard. Before we do so, let's populate<br />

MessageTable2 with a million rows of data of the same size <strong>and</strong> structure as the data in<br />

MessageTable1, so that our database file should be hovering somewhere around 1 GB<br />

in size.<br />

USE [DatabaseFor<strong>SQL</strong><strong>Backup</strong>s]<br />

GO<br />

DECLARE @messageData NVARCHAR(200)<br />

SET @messageData = 'This is a different message we are going to<br />

use to fill up the second table. We want to get<br />

this as close to 200 characters as we can to<br />

fill up the database as close to our initial<br />

size as we can.'<br />

INSERT INTO dbo.MessageTable2<br />

VALUES ( @messageData, GETDATE() )<br />

GO 1000000<br />

Listing 8-3: Populating the MessageTable2 table.<br />

Take a look in the <strong>SQL</strong>Data folder, <strong>and</strong> you'll now see that the data file is now about 1GB<br />

in size <strong>and</strong> the log file is still around 100 MB. Now that we have some more data to work<br />

with, Listing 8-4 shows the <strong>SQL</strong> <strong>Backup</strong> T-<strong>SQL</strong> script to perform a second full backup of<br />

our DatabaseFor<strong>SQL</strong><strong>Backup</strong>s database.<br />

EXECUTE master..sqlbackup '-<strong>SQL</strong> "BACKUP DATABASE [DatabaseFor<strong>SQL</strong><strong>Backup</strong>s]<br />

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

WITH DISKRETRYINTERVAL = 30, DISKRETRYCOUNT = 10, THREADCOUNT = 2, COMPRESSION = 1"'<br />

GO<br />

Listing 8-4: Second full backup of DatabaseFor<strong>SQL</strong><strong>Backup</strong>s using <strong>SQL</strong> <strong>Backup</strong> T-<strong>SQL</strong>.<br />

253

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

Saved successfully!

Ooh no, something went wrong!