Gerrit Mantel
Programs SQL_STORED_PROCEDURE - prc_check_database_backup

Main program

Nameprc_check_database_backup
Type_descSQL_STORED_PROCEDURE
CommentSQLServer Stored Procedure

PURPOSE
Check database backup state.

Check if the last backup of all ONLINE databases are not too old:
- The last weekly scheduled Full backup of user databases is max 180 hours old.
- The last daily scheduled Diff backup of user databases is max 36 hours old. Als also a recent full backup fulfils.
- The last transaction log backup of user databases scheduled with @log_backup_interval_minutes, is max 1.5
times @log_backup_interval_minutes minutes old. Also a recent Full- or Diff backup fulfils.
- The last full backup of system databases scheduled with @systemdb_max_hours, is max 1.5
times @systemdb_max_hours hours old.

Other checks:
- Check if readonly databases are in simple recovery model. Transaction log backups of readonly database get the
COPY_ONLY flag and are not in the backupchain and cannot be used for recover actions.
- Check if all databases have a "start backup", i.e. begin of backup chain.

List the database backup state (in de output grid).

On errors:
- Send the Error report to email_adddress if @email_address is given.
- Save the Error report to text file if @error_report_path is given.

PARAMETERS
- 1 @log_backup_interval_minutes INT Job schedule interval in minutes for the user databases transaction log backup, 15 / 30 / 60 (default).
- 2 @system_backup_interval_hours INT Job schedule interval in hours for the system databases backup, 1 / 2 / 4 (default) / 6 / 8 / 12 / 24.
- 3 @error_report_path VARCHAR(255) Path to deliver the error report file.
- 4 @email_address NVARCHAR(100) Email address to deliver error report mail.

EXAMPLES
-- Check database backup state using default backup intervals.
EXEC [dbo].[prc_check_database_backup] @error_report_path='C:\Data\MSSQL\error_report', @email_address='g.mantel@gmail.com';

USED OBJECTS
- dbo.fun_sqlversion (UDF in local database)
- dbo.fun_greatest_date2 (UDF in local database)
- dbo.fun_greatest_date3 (UDF in local database)
- dbo.fun_FolderExist (UDF in local database)
- dbo.prc_table2html (SP in local database)
- dbo.prc_save_text_to_utf8file (SP in local database)
- msdb.dbo.sp_send_dbmail

SQLSERVER CONFIGURATION
- OLE Automation has to be enabled.

HISTORY
2026-05-12 - Created procedure
2026-05-13 - Always select the database backup state list to the output grid.
- Added field Last_backup_type
- The @log_backup_interval_minutes minimum is now 15 minutes
2026-05-14 - Changed error_messages

TAGS
<program>
<description>Check database backup state</description>
<generic>1</generic>
<author>Gerrit Mantel</author>
<created>2026-05-12</created>
<lastmodified>2026-05-14</lastmodified>
</program>
DescriptionCheck database backup state
Minversion
Generic1
AuthorGerrit Mantel
Created2026-05-12 00:00:00
Lastmodified2026-05-14 00:00:00
Xp_cmdshell0
Ole_automation0
Subprogram_cnt11
Sourcecode

Sub programs

NameType descDescriptionMinversionGenericAuthorCreatedLastmodifiedXp cmdshellOle automation
fun_FolderExistSQL_SCALAR_FUNCTIONCheck if folder exists1Gerrit Mantel2015-11-24 00:00:002026-03-30 00:00:0001
fun_format_tablenameSQL_SCALAR_FUNCTIONFormat tablename1Gerrit Mantel2025-12-04 00:00:002025-12-04 00:00:0000
fun_getfieldSQL_SCALAR_FUNCTIONReturn the n-th field from a given string, between a given separator pattern1Gerrit Mantel2000-01-01 00:00:002024-02-09 00:00:0000
fun_greatest_date2SQL_SCALAR_FUNCTIONReturns the greatest of 2 dates1Gerrit Mantel2000-01-01 00:00:002024-02-09 00:00:0000
fun_greatest_date3SQL_SCALAR_FUNCTIONReturns the greatest of 3 dates1Gerrit Mantel2018-06-13 00:00:002024-02-09 00:00:0000
fun_nsplitSQL_TABLE_VALUED_FUNCTIONSplit delimited n-string into record values1Gerrit Mantel2005-03-21 00:00:002024-04-09 00:00:0000
fun_sqlversionSQL_SCALAR_FUNCTIONReturns the sqlversion1Gerrit Mantel2026-03-29 00:00:002026-03-29 00:00:0000
fun_text2htmlSQL_SCALAR_FUNCTIONReplace HTML/XML reserved characters in given text to HTML entity names1Gerrit Mantel2014-10-22 00:00:002025-11-26 00:00:0000
fun_uniquenameSQL_SCALAR_FUNCTIONReturn an unique name with format yyyy_mm_dd_hhmiss_nnnnnnn1Gerrit Mantel2000-01-01 00:00:002024-02-09 00:00:0000
prc_save_text_to_utf8fileSQL_STORED_PROCEDUREWrite text variable to utf-8 file with BOM1Gerrit Mantel2025-10-12 00:00:002025-10-12 00:00:0001
prc_table2htmlSQL_STORED_PROCEDUREGenerate HTML table for a given table or view14.01Gerrit Mantel2025-11-23 00:00:002026-02-07 00:00:0000