Solved

MS Cluster Failover - Reboot - Failback VBScript

Posted on 2010-11-23
6
1,319 Views
Last Modified: 2012-05-10
I'm wondering if anyone has a script out there that can identify resources on a multi-node cluster; fail over said cluster resource to a preferred node; reboot node; then failback the cluster resources to the Primary node?  I would greatly appreciate anyone's assistance on this?  
0
Comment
Question by:Leo2005
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:chillbill01
ID: 34218679
Yes, I have a script which is rather long but was used to reboot a four node MSCS, it uses a config.xml, where you place the names of the clusters.  I wrote it this way as we have 8 x 4 node clusters to reboot.  I haven't used it for a long time, but it should be okay. It may take some teaking for your environment.

 RestartCluster.vbs Config.xml
0
 

Author Comment

by:Leo2005
ID: 34219332
Chillbill01,  

Just to validate 1 variable, re: the config.xml; when you say "where you place the names of the clusters" do you refer to the resource name or server name.  I just need to confirm.

Thank you again!
0
 
LVL 3

Expert Comment

by:chillbill01
ID: 34219486
I am referring to the cluster name itself. The network name in the cluster resource group itself. The script connects to the name enumerates all the nodes with which node owns what resources and moves them to another node, reboots and moves the resources back. Hope this clears things up. Any issues let me know
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:FLPeople
ID: 34287769
This should work for you - just provide the cluster name in the first line. I'm assuming you only have 2 nodes. What's nice about this script it it won't reboot the primary node unless another viable node is found. Also, it waits for the cluster on the rebooted node to actually be back online, and can have a timeout specified to prevent an infinite loop. I did not test this but I did not detect any syntax errors.

Step 1: Search for another node and move to that, if no other node can be found, stop execution (via the WScript.Quit method)
Step 2: Reboot the old node and wait 1 minute (you must wait enough time here otherwise step 3 may execute and still detect online resources and attempt to move back to the node that is going down for a reboot)
Step 3: Query the old node repeatedly until clustered resources come online - once a clustered resource is online, it will be safe to move on to step 4
Step 4: Move resources back to the original node - note that it is also possible to find an available node using code from step 1
strClusterName = "CLUSTER1"





	'===== Step 1: MOVE CLUSTER TO NEW NODE =====



	Set objWMIService = GetObject("winmgmts:\\" & strClusterName & "\root\MSCluster")

	Set colItems = objWMIService.ExecQuery("Associators of {MSCluster_Cluster.Name='" & strClusterName & "'} WHERE AssocClass = MSCluster_ClusterToNode")

	strNodeToMoveTo = ""

	strOldNode = ""

	FoundNode = False

	For Each objitem In colItems

		Set colAGItems = objWMIService.ExecQuery("Associators of {MSCluster_Node.Name='" & objitem.Name & "'} WHERE AssocClass = MSCluster_NodeToActiveResource")

		rscCount = 0

		For Each objAGItem In colAGItems

			rscCount = (rscCount + 1)

		Next

		If rscCount = 0 Then

			strNodeToMoveTo = CStr(objitem.Name)

			FoundNode = True

		Else

			strOldNode = CStr(objitem.Name)

		End If

	Next

	If FoundNode = False Then

		' No nodes found

		WScript.Quit

	Else

		Set colResourceList = Nothing

            	Set colResourceList = objWMIService.ExecQuery("Select * from MSCluster_ResourceGroup")

		For Each objResource In colResourceList

			objResource.MoveToNewNode(strNodeToMoveTo)

		Next

	End If







	'===== Step 2: REBOOT OLD NODE =====



	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\" & strOldNode & "\root\cimv2")

	Set colOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

	For Each objOS in colOS

		objOS.Reboot()

	Next

	WScript.Sleep(60000)







	'===== Step 3: WAIT FOR OLD NODE TO COME BACK ONLINE =====

	'===== QUERY THE CLUSTER FOR AT LEAST 1 RESOURCE INDICATING ONLINE STATE =====

	On Error Resume Next

	OnlineResources = False

	TimeoutMultiplier = 60   '(in multiples of 10 seconds: 6 = 1 minute, 30 = 5 minutes, 60 = 10 minutes)

	While OnlineResources = False Or TimeoutMultiplier > 0

		Set objWMIService = GetObject("winmgmts:\\" & strOldNode & "\root\MSCluster")

        	Set colResourceList = objWMIService.ExecQuery("Select * from MSCluster_Resource")

        	For Each objResource In colResourceList

        		If objResource.State = 2 Then

				OnlineResources = True

			End If

		Next

		TimeoutMultiplier = (TimeoutMultiplier - 1)

		WScript.Sleep(10000)

		Set objWMIService = Nothing

        	Set colResourceList = Nothing

	Wend

	On Error Goto 0







	'===== Step 4: MOVE CLUSTER BACK TO OLD NODE =====



	Set objWMIService = GetObject("winmgmts:\\" & strClusterName & "\root\MSCluster")

        Set colResourceList = objWMIService.ExecQuery("Select * from MSCluster_ResourceGroup")

	For Each objResource In colResourceList

		objResource.MoveToNewNode(strOldNode)

	Next

Open in new window

0
 
LVL 3

Accepted Solution

by:
chillbill01 earned 250 total points
ID: 34308701
The script I wrote was created to handle as many nodes in a cluster as was required (to maximum an MNS cluster can handle.  You can also place as many cluster in as you want into the XML document and the script will work through them.  It was designed to allow the cluster to be rebooted overnight, saving an operations team time.
0
 

Author Closing Comment

by:Leo2005
ID: 34310513
Thank you, I was able to use this and it executed as designed.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now