daily database backup report (when not happened)

can you suggest how to do a SQL job that can query like
/* all for the previous day */
select count(*) from msdb..backupset where database_name = 'db1' and type ='d' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)
select count(*) from msdb..backupset where database_name = 'db2' and type ='d' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)
select count(*) from msdb..backupset where database_name = 'db3' and type ='d' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)
select count(*) from msdb..backupset where database_name = 'db4' and type ='d' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)

and if anyof them returns zero, then i want that to be sent as a email.

also for log backups:
select count(*) from msdb..backupset where database_name = 'db1' and type ='l' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)
select count(*) from msdb..backupset where database_name = 'db2' and type ='l' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)
select count(*) from msdb..backupset where database_name = 'db3' and type ='l' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)
select count(*) from msdb..backupset where database_name = 'db4' and type ='l' and CONVERT(VARCHAR(10),backup_start_date,101)  =CONVERT(VARCHAR(10),GETDATE()-1,101)

the goal is to have one email with all the databases that were not backed up..

Database Backup Report for <yesterdays date> for ServerA

DB1,DB3 - no FULL backups
DB1, DB2,DB4 - no Log backups

thank you.
LVL 5
25112Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David ToddSenior DBACommented:
Hi,

I forget exactly which check it is - 1 or 2 or 3 - but this (backup within last week) is checked in Brent Ozar's sp_Blitz.

That procedure has the code you want. And oh, by the way, its a good check on your current configuration.

HTH
  David
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
Just a comment:

Sending only an e-mail when an error occurs is not sufficient. Cause e-mail is not reliable. Consider a network error which interrupts your backup. The same error may suppress the sending of the e-mail.

For monitoring it's mandatory that you always post an e-mail, even when there is no error.
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
It will be more simple if you have something like:
IF NOT EXISTS (select 1 from msdb..backupset where backup_start_date,101 BETWEEN GETDATE()-1 AND GETDATE() THEN
   EXEC sendemail_procedure

Open in new window


But your backup job can be configured to send you an email if case of failure (open the job and configure it in the Notification area).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.