简体   繁体   中英

Create a batch script with cluster.exe for MS SQL Failover AOAG

I want to create a batch script using cluster.exe

My initial batch script( FAILOVER_TO_DRDB01.BAT ) is:

ECHO ON
cluster.exe node DRDB01 /status  -o  C:\FAILOVER_TO_DRDB01_LOG.txt

When I try to run it, there is no output created.

My main goal is that it will output this:

Listing status for node 'DRDB01':

Node           Node ID Status
-------------- ------- ---------------------
DRDB01               3 Joining

Once it sees that Status is Joining , it will run the following script:

net.exe stop clussvc  
net.exe start clussvc /forcequorum  

And once it failover, it will run the script below:

cluster.exe node DRDB01 /prop nodeweight=1 /prop:NodeWeight /status
cluster.exe node PDCDB01 /prop nodeweight=0 /prop:NodeWeight /status
cluster.exe node PDCDB02 /prop nodeweight=0 /prop:NodeWeight /status

I'm going to assume you want to find the node up at the end

@(setlocal enableextensions enabledelayedexpansion
  echo off 
  set "DRNode=DRDB01"
)

CALL :Main

( ENDLOCAL
  CALL :End
  EXIT /B 0
)

:Main
  REM Loop Until the status of the cluster node indefinitly:

  CALL :Do_Until_Status "%DRNode%" "Joining"

  CALL :Restart_Cluster_Svc

  CALL :Do_Until_Status "%DRNode%" "Up"

  CALL :On_Status_Up

GOTO :EOF


:Do_Until_Status
    cluster.exe node %~1 /status
    cluster.exe node %~1 /status | FIND /I "%~1" | FIND /I "%~2" && ( GOTO :EOF)
GOTO :Do_Until_Status

:Restart_Cluster_Svc

  REM stop the cluster service and start it using force quorum
  net.exe stop clussvc  
  net.exe start clussvc /forcequorum  

GOTO :EOF

:On_Status_Up
  cluster.exe node DRDB01 /prop nodeweight=1 /prop:NodeWeight /status
  cluster.exe node PDCDB01 /prop nodeweight=0 /prop:NodeWeight /status
  cluster.exe node PDCDB02 /prop nodeweight=0 /prop:NodeWeight /status
GOTO :EOF
  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM