Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 使用cluster.exe为MS SQL故障切换AOAG创建批处理脚本_Sql Server_Batch File_Failovercluster - Fatal编程技术网

Sql server 使用cluster.exe为MS SQL故障切换AOAG创建批处理脚本

Sql server 使用cluster.exe为MS SQL故障切换AOAG创建批处理脚本,sql-server,batch-file,failovercluster,Sql Server,Batch File,Failovercluster,我想使用cluster.exe创建批处理脚本 我的初始批处理脚本(FAILOVER_TO_DRDB01.BAT)是: 当我尝试运行它时,没有创建任何输出 我的主要目标是,它将输出以下内容: Listing status for node 'DRDB01': Node Node ID Status -------------- ------- --------------------- DRDB01 3 Joining 一旦它看到状态为加入,它将

我想使用cluster.exe创建批处理脚本

我的初始批处理脚本(FAILOVER_TO_DRDB01.BAT)是:

当我尝试运行它时,没有创建任何输出

我的主要目标是,它将输出以下内容:

Listing status for node 'DRDB01':

Node           Node ID Status
-------------- ------- ---------------------
DRDB01               3 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
  

谢谢,伙计,如果它已经启动了,我如何跳过:重启集群Svc
@(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