Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1380
  • Last Modified:

MS Cluster Failover - Reboot - Failback VBScript

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
Leo2005
Asked:
Leo2005
  • 3
  • 2
1 Solution
 
chillbill01Commented:
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
 
Leo2005Author Commented:
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
 
chillbill01Commented:
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
FLPeopleCommented:
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
 
chillbill01Commented:
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
 
Leo2005Author Commented:
Thank you, I was able to use this and it executed as designed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now