September 14, 2009 05:14 PM

Checking Backup Status on Multiple SQL Server Systems

Monitor backup status without having to rely on a third-party scheduler or backup tool
Rating: (0)
SQL Server Magazine
InstantDoc ID #102606
Making sure that every database on every server is backed up daily is one of the most important tasks on a DBA's to-do list. But how do you make sure every backup job has run every single day? What if someone has put the job on hold without your knowledge, especially if there are many DBAs on your team managing the environment? You want to make sure every single database has been backed up without relying on any particular backup method, whether it’s native SQL Server backup or a third-par...

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

It's pretty bad when you post an article in SQL Server Mag and the code is bad. Great concept, but not much help when your code doesn't work. It would be helpful if you post updated and correct code to your article.

Tim3/10/2010 3:53:45 PM


I had the same problem as Marcos when trying to create usp_mon_bacukp_status_of_all_servers. Received Msg 105, Level 15, State 1, Procedure usp_mon_backup_status_of_all_servers, Line 15
Unclosed quotation mark after the character string ' error. I tried everything I could think of. I even compared with the corrected code below, but it still didn't work. I emailed the author just a few minutes ago. I wonder if something is getting munged for some of us when we try to copy/paste from a browser. Just a theory.

Edward12/1/2009 2:17:32 PM


-- Replace your database name for yourdb

Use
Go

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

create proc usp_help_backup_status
as
begin
declare @sql nvarchar(4000)
declare @return_code int
declare @last_backup_date datetime
declare @server_name sysname

declare servers_cursor cursor for
select distinct server_name from .dbo.backup_status
order by server_name

open servers_cursor

fetch servers_cursor into @server_name

print '
print '---------------------------------------------------------------------------'
Print 'Databases not backed up in the last seven days'
print '---------------------------------------------------------------------------'
print '

while @@fetch_status = 0
begin



print '---------------------------------------------------------------------------'
print 'Server name: ' + @server_name
print '---------------------------------------------------------------------------'
print '

select database_name = convert(varchar, database_name),
backup_finish_date = convert(varchar(30), backup_finish_date, 121), type = convert(varchar, type)
from backup_status
where server_name = @server_name

fetch servers_cursor into @server_name

end

close servers_cursor

deallocate servers_cursor

end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

John11/23/2009 9:04:32 AM


I emailed the author and he send me updated code(see below). Works like a charm. Thanks!

-John

============================================

-- Replace your database name for yourdb

Use
Go

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

create procedure usp_mon_backup_status_of_all_servers
as
begin
declare @sql nvarchar(4000)
declare @return_code int
declare @last_backup_date datetime
declare @server_name sysname

declare servers_cursor cursor for
select srvname from master.dbo.sysservers
order by srvname

delete from backup_status

open servers_cursor

fetch servers_cursor into @server_name


while @@fetch_status = 0
begin


set @sql = '

set @sql = 'insert into backup_status SELECT server_name = '' + @server_name + '', database_name = convert(varchar, sd.name), backup_finish_date, type ' +
'FROM [' + @server_name + '].master.dbo.sysdatabases sd LEFT OUTER JOIN
(SELECT bs.database_name, backup_finish_date,
type = case type
when 'D' then 'Database'
when 'I' then 'Database Differential'
when 'L' then 'Log'
when 'F' then 'File or Filegroup'
end,
backup_size
FROM [' + @server_name + '].msdb.dbo.backupset bs,
(select database_name, max_backup_finish_date = max(backup_finish_date) from [' + @server_name + '].msdb.dbo.backupset
group by database_name) bs1
where bs.database_name = bs1.database_name
and bs.backup_finish_date = bs1.max_backup_finish_date) bs3
ON bs3.database_name = sd.name
where sd.name not in ('tempdb')
and
(backup_finish_date < getdate() - 7
or backup_finish_date is null)
ORDER BY sd.name ASC, backup_finish_date DESC'

-- print @sql

exec sp_executesql @sql

fetch servers_cursor into @server_name

end

close servers_cursor

deallocate servers_cursor

end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

John11/23/2009 9:00:34 AM


This is a grea idea. However, the scripts in Web Listing #1 and Web Listing #2 seem to both have errors. It isn't very useful if the code doesn't work.

John11/18/2009 12:29:59 PM


I think that there is a typo for the usp_mon_backup_status_of_all_servers. When I tried to create it I get the following error: Msg 105, Level 15, State 1, Procedure usp_mon_backup_status_of_all_servers, Line 46
Unclosed quotation mark after the character string '

Also, when I tried to create a Master SQL server to monitor a test server I get the following error:

===================================

MSX enlist failed for JobServer 'TESTSQL1'. (Microsoft.SqlServer.Smo)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.0.2531.0+((Katmai_PCU_Main).090329-101
5+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=MSX+enlist
+JobServer&LinkId=20476

------------------------------
Program Location:

at Microsoft.SqlServer.Management.Smo.Agent.JobServer.MsxEnlist(String masterServer, String location)
at Microsoft.SqlServer.Management.SqlManagerUI.EnlistTsxActions.DoAction(ProgressItemCollection actions, Int32 index)
at Microsoft.SqlServer.Management.SqlStudio.Controls.ProgressItemCollection.DoWorkOnThread()

===================================


The web link for help had the typical Microsoft message 'We're sorry' but I did find some information that might be related to this problem.

http://msdn.microsoft.com/en-us/library/ms365379.aspx

I am not sure if I should be making any changes to the MsxEncryptChannelOptions registry entry. It wouldn't be a wizard if you had to mess around with the regisry. Please let me know if I am doing something wrong, I would like to implement this for my SQL enviorment.

Thank You

Ray10/20/2009 2:13:58 PM


Nice to have, I just wonder if it will works fine for thousands of servers.

Take Care!

Marcos10/16/2009 9:00:15 AM


excellent

Diane10/8/2009 1:01:47 PM


You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS