Solved

MS Cluster Failover - Reboot - Failback VBScript

Posted on 2010-11-23
6
1,335 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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