In my last post, “10 SQL Server Disaster Recovery Solutions” I discussed about 10 solutions which were available for SQL Server and discussed about SQL Server Database backup which most basic form of disaster recovery for SQL Server and one that was being practiced in every situation.
If SQL Server database backups are too much critical, then how can I verify that database backups are being backup as per backup policy.
What all should be monitored for SQL Server Database Backup considering Disaster recovery in mind.
- Ensure that Databases are backing up as per plan
- What all databases which are not getting backup up
- Database backups are good and can be recovered in case restore ins required.
Let’s build solution for these three critical item for ensuring GOOD SQL Database Backups.
How can I monitor that all Databases are backing up as per plan ?
Here is a quick script which will let you know
- what all databases are being backup
- When those backup happened
- Backup window – Backup Start Time and Backup End Time
- What Type of backup is being taken ?
- Size of Database backup
- Location, where backup has been performed
/*------------------------------------------------------------------------------------------------------------------------------- Description : This SQL Script will list down all SQL Server backups which were taken in last 10 days with details -- Copyright 2012 - DBATAG -- Author : DBATAG -- Created on : 02/06/2012 -- Version : 1.0 -- Dependencies : -- Compatibility : This will work on SQL Server 2000, 2005, 2008, 2008 R2 and even in SQL Server 2012 ----------------------------------------------------------------------------------------------------------------------------*/ SELECT CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, bs.database_name, bs.backup_start_date, bs.backup_finish_date, bs.expiration_date, CASE bs.type WHEN 'D' THEN 'Full Database' WHEN 'L' THEN 'Log' WHEN 'I' THEN 'Differential' WHEN 'F' THEN 'File Level' WHEN 'G' THEN 'File Level Differential' WHEN 'P' THEN 'Partial' WHEN 'Q' THEN 'Differential partial' END AS backup_type, convert(varchar,cast(bs.backup_size/1024/1024 as money),10) as 'Backup Size in MB', bmf.logical_device_name, bmf.physical_device_name, bs.name AS backupset_name, bs.description FROM msdb.dbo.backupmediafamily bmf INNER JOIN msdb.dbo.backupset bs ON bmf.media_set_id = bs.media_set_id WHERE (CONVERT(datetime, bs.backup_start_date, 102) >= GETDATE() - 10) ORDER BY bs.database_name, bs.backup_finish_date
This one Script will work on all versions and editions of SQL Server including 2000, 2005, 2008, 2008 R2 and even in SQL Server 2012
This report covers all backup which are even being taken using any software like TIVOLI, SQL LITE, VERITAS BACKUP agents etc.
Script OUTPUT
How can I monitor What all Databases are not being backup in last 24 hours?
This is more much more important, to know what all databases are not being backup in last couple of days / hours.
SQL Script to List down which of the databases have not been getting backed up
/*------------------------------------------------------------------------------------------------------------------------------- -- Description : This SQL Script will list down all SQL Server backups which were not backup in last 2 days -- Copyright 2012 - DBATAG -- Author : DBATAG -- Created on : 02/06/2012 -- Version : 1.1 -- Dependencies : -- Compatibility : This will work on SQL Server 2000, 2005, 2008, 2008 R2 and even in SQL Server 2012 ----------------------------------------------------------------------------------------------------------------------------*/ SELECT CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, bs.database_name, MAX(bs.backup_finish_date) AS last_db_backup_date, DATEDIFF(hh, MAX(bs.backup_finish_date), GETDATE()) AS [Backup Age (Hours)] FROM msdb.dbo.backupset bs WHERE bs.type = 'D' GROUP BY bs.database_name HAVING (MAX(bs.backup_finish_date) < DATEADD(hh, - 48, GETDATE())) UNION --Databases without any backup history SELECT CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, master.dbo.sysdatabases.NAME AS database_name, NULL AS [Last Data Backup Date], 9999 AS [Backup Age (Hours)] FROM master.dbo.sysdatabases LEFT JOIN msdb.dbo.backupset bs ON master.dbo.sysdatabases.name = bs.database_name WHERE bs.database_name IS NULL AND master.dbo.sysdatabases.name <> 'tempdb' ORDER BY bs.database_name
SCRIPT OUTPUT
Now we have verified that all database are being backup up. Now there is a need to verify these database backups to check weather using these backups, will be able to re build SQL Server database, in case required? So here is next,
How to check Database backups are good and can be recovered in case restore ins required.
SQL Server inbuilt has a tool which verifies SQL Server database backup. Verify will detect any sort of errors in backup file. By using SQL Server native tool we can verify
- That the backup set is complete and all volumes are readable.
- ALL PADE ID are available and readable
SQL Script to Verify SQL Server Database backup file
RESTORE VERIFYONLY FROM DISK = 'C:\TEMP\SQLBAckup\DBATAG\Reportserver_20120206.bak' ;
OUTPUT
NOTE - The above mention Script will not perform any actual restore on server. This will just verify backup media.
NEXT, Check out my previous post, “SQL Script for getting Backup Information” to get answers for following questions
SQL Script to know when all was last backup was being performed ?
SQL Script to know when all was last backup was being performed and what type of backup was taken ?
SQL Script to what type of backup is being configured and when it was last run?
The post How to Monitor SQL Server Backups ? appeared first on SQL Server Training | Tutorials | How to's.