使用 cluster.exe 为 MS SQL 故障转移 AOAG 创建批处理脚本
Create a batch script with cluster.exe for MS SQL Failover AOAG
我想使用 cluster.exe
创建批处理脚本
我的初始批处理脚本(FAILOVER_TO_DRDB01.BAT)是:
ECHO ON
cluster.exe node DRDB01 /status -o C:\FAILOVER_TO_DRDB01_LOG.txt
当我尝试 运行 它时,没有创建输出。
我的主要目标是它会输出这个:
Listing status for node 'DRDB01':
Node Node ID Status
-------------- ------- ---------------------
DRDB01 3 Joining
一旦它看到 Status 是 Joining,它将 运行 以下脚本:
net.exe stop clussvc
net.exe start clussvc /forcequorum
一旦故障转移,它将运行下面的脚本:
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
我假设您想在末尾向上找到节点
@(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
我想使用 cluster.exe
创建批处理脚本我的初始批处理脚本(FAILOVER_TO_DRDB01.BAT)是:
ECHO ON
cluster.exe node DRDB01 /status -o C:\FAILOVER_TO_DRDB01_LOG.txt
当我尝试 运行 它时,没有创建输出。
我的主要目标是它会输出这个:
Listing status for node 'DRDB01':
Node Node ID Status
-------------- ------- ---------------------
DRDB01 3 Joining
一旦它看到 Status 是 Joining,它将 运行 以下脚本:
net.exe stop clussvc
net.exe start clussvc /forcequorum
一旦故障转移,它将运行下面的脚本:
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
我假设您想在末尾向上找到节点
@(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