Skip to content

Commit 9c833f3

Browse files
committed
cleanup and standardize naming for AG scripts
1 parent 095276a commit 9c833f3

15 files changed

+484
-543
lines changed
File renamed without changes.

Availability Groups/AG_Monitor.sql renamed to AG - Monitor.sql

Lines changed: 172 additions & 172 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.

AG - post-zerto failover.ps1

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
#https://docs.microsoft.com/en-us/sql/sql-server/failover-clusters/windows/change-the-ip-address-of-a-failover-cluster-instance?view=sql-server-2017
3+
#https://docs.microsoft.com/en-us/powershell/module/failoverclusters/set-clusterparameter?view=win10-ps
4+
5+
#TODO: Uncomment Set-ClusterParameter commands for safety.
6+
7+
#This is for N01
8+
#For N02, change the first two variable names below, $Server_IP_Prod and $Server_IP_DR
9+
10+
#You may want to change these variables to "_DC1" and "_DC2"
11+
$Server_IP_Prod = "10.0.3.179"
12+
$Server_IP_DR = "10.35.135.161"
13+
$Cluster_IP_Prod = "10.0.3.181"
14+
$Cluster_IP_DR = "10.35.135.163"
15+
16+
$cluster_resource_name  = "Cluster IP Address" #not from Failover Cluster Manager or SQL, but from the Get-ClusterResource cmdlet. Usually "Cluster IP Address"
17+
#$listener_name = "GSFSQASCS_172.20.63.21" #not from Failover Cluster Manager or SQL, but from the Get-ClusterResource cmdlet. USually it's "AGname_IPAddress"
18+
19+
#Figure out where we are right now.
20+
$Current_Cluster_ipaddress = get-clusterresource -Name "Cluster IP Address" | Get-ClusterParameter -Name "Address" | Select-Object Value
21+
$CurrentIP = get-netipaddress | Where-Object -FilterScript { $_.IPAddress -contains $Server_IP_Prod -or $_.IPAddress -contains $Server_IP_DR} | Select-Object IPAddress
22+
23+
If ($currentIP -match $Server_IP_Prod -and $Current_Cluster_ipaddress -match $Cluster_IP_Prod )
24+
{
25+
#We're in PROD and Cluster agrees, nothing to do
26+
}
27+
ElseIf ($currentIP -match $Server_IP_DR -and $Current_Cluster_ipaddress -match $Cluster_IP_DR )
28+
{
29+
#We're in DR and Cluster agrees, nothing to do
30+
}
31+
ElseIf ($currentIP -match $Server_IP_DR -and $Current_Cluster_ipaddress -match $Cluster_IP_Prod )
32+
{
33+
#We've failed over to DR. The Server's IP has been updated, but the Cluster hasn't yet.
34+
35+
import-module sqlps
36+
#Add new IP for xerto destination to AG Listener before the failover
37+
#this next step should only need to be done once.
38+
Add-SqlAvailabilityGroupListenerStaticIp -Path "SQLSERVER:\SQL\localhost\DEFAULT\AvailabilityGroups\SCRSQL\AvailabilityGroupListeners\scrsqlp01vip" -StaticIp "10.35.135.164/255.255.255.0" -Script
39+
40+
41+
#Verify
42+
Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
43+
44+
$new_ip = $Cluster_IP_DR
45+
$Current_IP_Cluster_Resource_Name  = Get-ClusterResource -Name $cluster_resource_name
46+
47+
#Subnet mask will not change after the Xerto failover
48+
#$new_subnet_mask = "255.255.255.0" #need to determine this info after xerto failover
49+
   
50+
$parameter1 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,Address,$new_ip
51+
#Subnet mask will not change after the Xerto failover
52+
#$parameter2 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,SubnetMask,$new_subnet_mask
53+
$parameters = $parameter1 #,$parameter2
54+
 
55+
#Change the IPs
56+
#Uncomment the below line to actually have an impact! Commented for safety.
57+
$parameters #| Set-ClusterParameter
58+
 
59+
60+
#This step would happen once after the changes
61+
#Make the change happen
62+
Stop-ClusterResource $cluster_resource_name
63+
Start-ClusterResource $cluster_resource_name
64+
}
65+
66+
ElseIf ($currentIP -match $Server_IP_Prod -and $Current_Cluster_ipaddress -match $Cluster_IP_DR )
67+
{
68+
#We've failed back to PROD. The Server's IP has been updated, but the Cluster hasn't yet.
69+
70+
#Verify
71+
Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
72+
73+
$new_ip = $Cluster_IP_DR
74+
$Current_IP_Cluster_Resource_Name  = Get-ClusterResource -Name $cluster_resource_name
75+
76+
#Subnet mask will not change after the Xerto failover
77+
#$new_subnet_mask = "255.255.255.0" #need to determine this info after xerto failover
78+
   
79+
$parameter1 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,Address,$new_ip
80+
#Subnet mask will not change after the Xerto failover
81+
#$parameter2 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,SubnetMask,$new_subnet_mask
82+
$parameters = $parameter1 #,$parameter2
83+
 
84+
#Change the IPs
85+
#Uncomment the below line to actually have an impact! Commented for safety.
86+
$parameters #| Set-ClusterParameter
87+
 
88+
89+
#This step would happen once after the changes
90+
#Make the change happen
91+
Stop-ClusterResource $cluster_resource_name
92+
Start-ClusterResource $cluster_resource_name
93+
 
94+
95+
}
96+
97+
#Verify
98+
Get-ClusterResource $cluster_resource_name | Get-ClusterParameter

0 commit comments

Comments
 (0)