Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS Cluster Failover - Reboot - Failback VBScript

Posted on 2010-11-23
6
Medium Priority
?
1,363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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