Identify SQL Server Databases Not Recently Backed Up Using Policy Based Management
By: Ashish Kumar Mehta | Updated: 2010-09-22 | Comments (5) | Related: More > Policy Based Management
As the DBA, you need to determine if there are any databases in your production environment which have not had a full backup in the last 24 hours. In this tip we cover the step by step process for setting up a policy to identify all the databases which are not backed up in the last 24 hours.
Database Administrators can use Policy Based Management (PBM) to identify databases which have not backed up in the last 24 hours. You can follow the below steps to create and evaluate the policy. It's assumed that the DBA is taking full backups of all the user databases once a day. However, there are certain exceptions when Full Backups for a database are performed once in a week especially for very large databases, but for this example we are expecting all databases to be backed up daily.
If you are not familiar with Policy Based Management (PBM) then you can start with the following tip: Using Policy-Based Management in SQL Server 2008.
1. Connect to SQL Server 2008 instance using SQL Server 2008 Management Studio and expand Management -> Policy Management and then right click Policies and select New Policy... as shown in the snippet below.
2. In the Create New Policy window provide the name of the policy as "Identify Databases Not Backed up in the Last 24 hours". In Check condition you need to click the New condition.... option to open up the Create New Condition window.
3. In the Create New Condition window you need to provide the name of the condition as "Databases Not Backed up in the Last 24 hours" and then select the Facet "Database". Under Expression select Field value as @LastBackupDate and choose operator value as ' >= ' and then the value as DateAdd('HH', -25, GetDate()) as shown in the below snippet. Click OK to save the condition and to return to the parent Create New Policy window. This will check for any backup 25 hours older than now.
- Use @LastBackupDate field to identify the date and time when the database was last backed up
- Use @LastDifferentialBackupDate to identify the data and time when the last differential backup was performed
- Use @LastLogBackupDate to identify the data and time when the transaction log was last backed up
4. In Create New Policy, by default Every Database option under Against targets will be checked as shown in the below snippet. Click OK to create the policy.
5. Once your policy is created, the next step will be to evaluate the policy. Right click the policy and select the Evaluate option from the drop down list as shown in the below snippet.
6. The below snippet shows the result set returned by the policy. We can see that for one of the database AdventureWorks the policy has failed. The reason for the failure is AdventureWorks database was not backed up in the last 24 hours.
7. When you click a "View..." link under Details, you will be able to see a detailed result for the AdventureWorks database. The expected value is "Current Date - 25 hours", however the actual value reflects the time the last full backup was done for the AdventureWorks database.
After you find the databases out of compliance, the next step would be to perform full backups of these databases.
- Setup a policy similar to this to check that your databases are backed up according to your backup plan.
- Review Using Policy-Based Management in SQL Server 2008
- Read more tips on Policy Based Management
Last Updated: 2010-09-22
About the author
View all my tips