Database backup


Job details

Name: Database backup
Platform: Sqlserver
Category: Availability
Description: This procedure analyzes the backup statistics (type D and I) from the msdb.dbo.backupset table (excluding the system databases: master, model and msdb).
Long description: This procedure analyzes the backup statistics (type D and I) from the msdb.dbo.backupset table (excluding the system databases: master, model and msdb).
Version: 2.4
Default schedule: 10 6 * *
Requires engine install: Yes
Compatibility tag: .[type=‘instance’ & databasetype=‘sqlserver’]/instance[maj_version > ‘2012′ & hasengine=‘YES’ & (engine_edition = ‘Microsoft SQL Server’ engine_edition = ‘Azure SQL Managed Instance’)]

Parameters

Name Default value Description
ignore databases dbwatch% The list of databases to be ignored (separated by comma).
backup date threshold 48 A warning/alarm is triggered if the number of hours since the database was last backed up is greater than the parameter value.
return status when missing backup 2 Return status value (ALARM – 2, WARNING – 1, or OK – 0) when missing backup of a database.
return status when old backup 2 Return status value (ALARM – 2, WARNING – 1, or OK – 0) when the last backup date is older than the “backup date threshold” parameter value.
exclude databases in SIMPLE recovery mode NO If set to YES the alert will exclude all databases configured with SIMPLE recovery mode.
exclude databases if new 24 If the database has been created within the last 24 hours (default value), no warning/alarm will be triggered.
exclude databases in Always On availability groups YES If set to YES the alert will exclude all databases in Always On availability groups.
exclude log shipping databases YES If set to YES the alert will exclude all databases in a log shipping configuration (databases in msdb.dbo.log_shipping_secondary_databases table).
exclude standby databases YES If set to YES the alert will exclude all databases in state online as read-only, with restore log allowed (IsInStandBy property set to TRUE).

Job Summary

SELECT database_name, MAX(backup_finish_date) AS last_backup_date FROM msdb.dbo.backupset WHERE type IN ('D','I') AND database_name NOT IN ('master', 'model', 'msdb') GROUP BY database_name;

Report Templates and Presentations

Old Backups

Database Name Status Last Backup Backup Age
ExampleDB Online 2023-01-01 23:59 48

Missing Backups

Database Name Created
NewDB 2023-01-20

Most Recent Backups

Database Name Backup Finish Backup Start Elapsed Time Expiration Date Size (MB) Device Name Physical Location Set Name Description
ExampleDB 2023-01-01 23:59 2023-01-01 22:00 119 2023-06-01 5120 Device001 C:\backups\file.bak Set001 Full backup

Implementation Overview
This job includes creating or altering necessary stored procedures and tables to facilitate this checking. Specific details are:

Dependencies and Cleanup
The task has dependencies on its own previously defined procedures, and in cases of a failure during task execution, a cleanup is performed by truncating the “dbw_ignore_db” table to reset the state.