Skip to content

Backup Status - Execution Timeouts and Improvements #43

Open
@agougo

Description

This script needs to be improved as it is not designed to function in HA environments with critical Data.

If you have an application with critical data and a backup is running every 15 minutes (e.g. for the transaction log) this will create a lot of entries in the database. This script will need to go through these entries one by one before applying thresholds. To my experience this script will run forever and will create a memory issue on your PROD MSSQL server. If you set a timeout of 60 seconds then it will timeout and will never give you back any useful data.

A better approach will be to change the query in Get-IcingaMSSQLBackupOverallStatus.psm1 to something like this:

$Query = "SELECT
            msdb.dbo.backupset.database_name,
            msdb.dbo.backupset.backup_start_date,
            msdb.dbo.backupset.backup_finish_date,
            msdb.dbo.backupset.is_damaged,
            msdb.dbo.backupset.type,
            msdb.dbo.backupset.backup_size,
			msdb.dbo.backupset.backup_set_uuid,
            msdb.dbo.backupmediafamily.physical_device_name,
            msdb.dbo.backupmediafamily.device_type,
            sys.databases.state,
            sys.databases.recovery_model,
            DATEDIFF(MI, msdb.dbo.backupset.backup_finish_date, GETDATE()) AS last_backup_hours,
            DATEDIFF(MI, msdb.dbo.backupset.backup_start_date,  msdb.dbo.backupset.backup_finish_date) AS last_backup_duration_min
        FROM msdb.dbo.backupmediafamily
            INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id
            LEFT JOIN sys.databases ON sys.databases.name = msdb.dbo.backupset.database_name
			INNER JOIN (select max(backup_start_date) as backup_start_date, database_name, type
				from msdb.dbo.backupset
				--where database_name = 'CBO'
				--where type in ('D', 'I', 'L')
				group by msdb.dbo.backupset.database_name, msdb.dbo.backupset.type) a
				on a.database_name = msdb.dbo.backupset.database_name
				and a.type = msdb.dbo.backupset.type
				and a.backup_start_date = msdb.dbo.backupset.backup_start_date
		WHERE sys.databases.source_database_id IS NULL
        ORDER BY
            msdb.dbo.backupset.database_name,
            msdb.dbo.backupset.backup_finish_date"

And all counting should be changed to minutes, not days! For example

$LastBackupLogAge = ($Entry.last_backup_hours * 60 * 60)
should be changed to $LastBackupLogAge = ($Entry.last_backup_hours * 60)

'LastBackupAge' = (([long]$Entry.last_backup_hours) * 60 * 60);
should be changed to 'LastBackupAge' = (([long]$Entry.last_backup_hours) * 60);

and so on ...

In addition to the above, the script will not give you the backup of a specific database and will put tremendous pressure on your machine. You need to change

$BackupSet = Get-IcingaMSSQLBackupOverallStatus -SqlConnection $SqlConnection;
to
$BackupSet = Get-IcingaMSSQLBackupOverallStatus -SqlConnection $SqlConnection -IncludeDatabase $IncludeDatabase;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions