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 2: Planning, Storage <strong>and</strong> Documentation<br />

This information can be harvested in a number of different ways, but ideally will be<br />

scripted <strong>and</strong> automated. Listing 2-3 shows two scripts that will capture just some of this<br />

information; please feel free to adapt <strong>and</strong> amend as is suitable for your environment.<br />

SELECT d.name ,<br />

MAX(d.recovery_model) ,<br />

is_Password_Protected , --<strong>Backup</strong>s Encrypted:<br />

--Last Full Database <strong>Backup</strong>:<br />

MAX(CASE WHEN type = 'D' THEN backup_start_date<br />

ELSE NULL<br />

END) AS [Last Full Database <strong>Backup</strong>] ,<br />

--Last Transaction Log <strong>Backup</strong>:<br />

MAX(CASE WHEN type = 'L' THEN backup_start_date<br />

ELSE NULL<br />

END) AS [Last Transaction Log <strong>Backup</strong>] ,<br />

--Last Differential Log <strong>Backup</strong>:<br />

MAX(CASE WHEN type = 'I' THEN backup_start_date<br />

ELSE NULL<br />

END) AS [Last Differential <strong>Backup</strong>] ,<br />

--How Often are Transaction Logs Backed Up:<br />

DATEDIFF(Day, MIN(CASE WHEN type = 'L' THEN backup_start_date<br />

ELSE 0<br />

END),<br />

MAX(CASE WHEN type = 'L' THEN backup_start_date<br />

ELSE 0<br />

END)) / NULLIF(SUM(CASE WHEN type = 'I' THEN 1<br />

ELSE 0<br />

END), 0) [Logs BackUp count] ,<br />

--Average backup times:<br />

SUM(CASE WHEN type = 'D'<br />

THEN DATEDIFF(second, backup_start_date,<br />

<strong>Backup</strong>_finish_date)<br />

ELSE 0<br />

END) / NULLIF(SUM(CASE WHEN type = 'D' THEN 1<br />

ELSE 0<br />

END), 0) AS [Average Database<br />

Full <strong>Backup</strong> Time] ,<br />

SUM(CASE WHEN type = 'I'<br />

THEN DATEDIFF(second, backup_start_date,<br />

<strong>Backup</strong>_finish_date)<br />

ELSE 0<br />

END) / NULLIF(SUM(CASE WHEN type = 'I' THEN 1<br />

80

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

Saved successfully!

Ooh no, something went wrong!