-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-SqlFailoverSafety.ps1
More file actions
76 lines (58 loc) · 2.73 KB
/
Test-SqlFailoverSafety.ps1
File metadata and controls
76 lines (58 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<#
.SYNOPSIS
Prevents accidental Geo-Failovers for FCI (Failover Cluster Instances).
.DESCRIPTION
This script acts as a "Safety Latch" before any patching or maintenance event.
It identifies if a SQL Instance is an FCI or an AG.
CRITICALLY: It compares the IP Subnet of the Current Node vs. the Target Node.
If the Subnets differ (implying a WAN link) and the instance is an FCI, it returns a HARD FAIL.
.AUTHOR
Gavin Dobbs (LordTalyn)
.EXAMPLE
Test-SqlFailoverSafety -ClusterName "SQL-CLUST-01" -InstanceName "MSSQLSERVER"
#>
param (
[Parameter(Mandatory=$true)]
[string]$ClusterName,
[Parameter(Mandatory=$true)]
[string]$InstanceName
)
Import-Module FailoverClusters
Write-Host "Please wait... Interrogating Cluster Topology for [$ClusterName]" -ForegroundColor Cyan
# 1. Identify the Current Owner (Active Node)
$resourceParams = Get-ClusterGroup -Cluster $ClusterName | Where-Object {$_.Name -match $InstanceName}
$activeNode = $resourceParams.OwnerNode.Name
# 2. Identify the Passive Node(s)
$allNodes = Get-ClusterNode -Cluster $ClusterName
$passiveNodes = $allNodes | Where-Object {$_.Name -ne $activeNode}
Write-Host "Active Node: $activeNode" -ForegroundColor Green
# 3. NETWORK TOPOLOGY CHECK (The BECU Fix)
# Get IP Subnet of Active Node
$activeIP = Get-ClusterNode -Name $activeNode | Get-ClusterOwnerNode | Get-ClusterResource | Where-Object {$_.ResourceType -eq "IP Address"}
# Note: In a real script, we'd dig deeper into Get-NetIPAddress, but for logic flow:
foreach ($node in $passiveNodes) {
# Pseudo-Code for Subnet Logic to keep it readable for the Repo
# In production, we compare the first 3 octets of the IPv4 address
$activeSubnet = (Get-ClusterNode $activeNode).Description # Assuming Admin puts Site in Desc
$targetSubnet = $node.Description
Write-Host "Checking Path: $activeNode -> $($node.Name)" -NoNewline
# 4. THE LOGIC GATE
# If the nodes are in different "Sites" or "Subnets"
if ($activeSubnet -ne $targetSubnet) {
Write-Warning " [WARNING] GEO-DISTANCE DETECTED"
# Check if it's an FCI (Shared Storage)
# We assume it is an FCI for this specific failure mode
$isFCI = $true
if ($isFCI) {
Write-Host "CRITICAL STOP: Attempting to failover FCI across WAN links." -ForegroundColor Red
Write-Host "REASON: 4.5TB Data Move Risk. Latency > 100ms." -ForegroundColor Red
Write-Host "ACTION: FAILOVER BLOCKED." -ForegroundColor Red
Return $false
}
}
else {
Write-Host " [SAFE] Local Subnet Failover." -ForegroundColor Green
}
}
Write-Host "Logic Check Complete. Safe to Proceed." -ForegroundColor Cyan
Return $true