Solved

MS Cluster Failover - Reboot - Failback VBScript

Posted on 2010-11-23
6
1,343 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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