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

/* Find date of final INSERT from previous statement<br />

This is to help us with the RESTORE process<br />

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

GO<br />

SELECT TOP(1) MessageData,MessageDate<br />

FROM dbo.MessageTable1<br />

WHERE MessageData LIKE 'MessageTable1%'<br />

ORDER BY MessageDate DESC<br />

-- Output: 2011-12-06 10:41:36.540<br />

*/<br />

INSERT INTO dbo.MessageTable2<br />

VALUES ( 'MessageTable2, the true answer is 42!', GETDATE() )<br />

GO 42<br />

-- final insert time: 2011-12-06 10:42:45.897<br />

--Disaster strikes!<br />

DROP TABLE dbo.MessageTable2<br />

GO<br />

Listing 8-16: Disaster strikes MessageTable2.<br />

In this simple example, we have the luxury of knowing exactly when each event occurred.<br />

However, imagine this is a busy production database, <strong>and</strong> we only find out about the<br />

accidental table loss many hours later. Listing 8-17 simulates one of our regular, scheduled<br />

log backups, which runs after the data loss has occurred.<br />

USE [master]<br />

GO<br />

EXECUTE master..sqlbackup '-<strong>SQL</strong> "BACKUP LOG [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_Log_3.sqb''<br />

WITH DISKRETRYINTERVAL = 30, DISKRETRYCOUNT = 10,<br />

COMPRESSION = 1, THREADCOUNT = 2"'<br />

Listing 8-17: A post-disaster log backup.<br />

281

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

Saved successfully!

Ooh no, something went wrong!