【问题标题】:Create a batch script with cluster.exe for MS SQL Failover AOAG使用 cluster.exe 为 MS SQL 故障转移 AOAG 创建批处理脚本
【发布时间】:2020-09-01 23:14:21
【问题描述】:

我想使用 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

【问题讨论】:

    标签: sql-server batch-file failovercluster


    【解决方案1】:

    我假设你想在最后找到节点 up

    @(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
      
    

    【讨论】:

    • 谢谢哥们,如果它已经启动了,我将如何跳过:Restart_Cluster_Svc
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多