Search

Wednesday, July 27, 2011

Code to fail an cluster resource back to the prefered owner

This code can be used to fail a cluster group. In this case the name of the cluster group is SQL2_SQL2K5. If it is on the PRI node,SERVER-PRI , we fail it back.

SET NOCOUNT ON
DECLARE @ReturnCode int
DECLARE @Node varchar(100)
CREATE TABLE #Messages(Message nvarchar(255))
INSERT INTO #Messages
EXEC @ReturnCode = master..xp_cmdshell 'cluster group SQL2_SQL2K5'
set @Node =(SELECT left(right(message,23),14)
FROM #Messages where message like'%online%' )
DROP TABLE #Messages
select @Node
if upper(@Node) = 'SERVER-PRI'
exec master..xp_cmdshell 'cluster group SQL2_SQL2K5 /move'
end

No comments:

Post a Comment