Home Forums SQL Server 2008 T-SQL (SS2K8) Send Alert when no log backup completed in 24 hours RE: Send Alert when no log backup completed in 24 hours

  • to expand on what george posted you can create a procedure and schedule an agent job to run it. the procedure would also email the results (if any) using sp_send_dbmail http://msdn.microsoft.com/en-us/library/ms190307.aspx

    im currently working on some example code and will post when im done

    EDIT:

    Here is a rough sample and will probably need to be tweaked to make it work specifically as you want so it will email you through the dbmail system if there is an error. you would just set up an agent job to run the SP once a day

    CREATE PROCEDURE usp_NoTlogBackup (@Length INT)

    AS

    DECLARE @BadDatabases VARCHAR(8000)

    DECLARE @Body VARCHAR(8000)

    SELECT @BadDatabases = STUFF(

    (select ', ' + cast(a.database_name as varchar(100))

    from

    (

    select [name] as database_name

    from master.dbo.sysdatabases

    where databasepropertyex([name], 'recovery') in ('FULL','BULK_LOGGED')

    and databasepropertyex([name], 'isinstandby') = 0

    and databasepropertyex([name], 'status') = 'online'

    and databasepropertyex([name], 'updateability') = 'read_write'

    and [name] not in ('model','tempdb')

    ) a

    left join msdb.dbo.backupset b

    on a.database_name = b.database_name

    and b.type='L'

    and datediff(hour,b.backup_finish_date,getdate()) < @Length

    where b.database_name is null

    FOR XML PATH ('')

    ),1,2,'')

    IF (@BadDatabases IS NOT NULL)

    BEGIN

    SET @Body = 'On ' + @@SERVERNAME + ' The following Databases do not have Tlog backups: ' + @BadDatabases

    EXEC msdb.dbo.sp_send_dbmail @profile_name = 'profile_name',

    @recipients = 'your@email.com',

    @from_address = 'ServerName@from.com',

    @body = @Body

    END


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]