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
1
+ # Post-Zerto failover script for handling changes to Availability Groups.
2
+ # WORK IN PROGRESS. May need to be adjusted for your environment.
9
3
10
4
# You may want to change these variables to "_DC1" and "_DC2"
11
5
$Server_IP_Prod = " 10.0.3.179"
12
6
$Server_IP_DR = " 10.35.135.161"
13
7
$Cluster_IP_Prod = " 10.0.3.181"
14
8
$Cluster_IP_DR = " 10.35.135.163"
9
+ $Listener_IP_Prod = " 10.0.3.182"
10
+ $Listener_IP_DR = " 10.35.135.164"
15
11
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"
12
+ # not from Failover Cluster Manager or SQL, but from the Get-ClusterResource cmdlet. Usually "Cluster IP Address"
13
+ $cluster_resource_name = " Cluster IP Address"
14
+ # Get the listener object name, which changes. Follows this pattern: "AGNAME_ListenerIP", example, SCRSQL_10.0.3.182
15
+ $listener_resource_name = Get-ClusterResource - Name " SCRSQL_*" | Where-Object - FilterScript { $_.ResourceType -contains " IP Address" } | Select-Object Name
16
+ # Name of the AG, which we'll attempt to start at the end.
17
+ $AG_resource_name = " SCRSQL"
18
18
19
19
# Figure out where we are right now.
20
20
$Current_Cluster_ipaddress = get-clusterresource - Name " Cluster IP Address" | Get-ClusterParameter - Name " Address" | Select-Object Value
@@ -32,67 +32,93 @@ ElseIf ($currentIP -match $Server_IP_DR -and $Current_Cluster_ipaddress -match $
32
32
{
33
33
# We've failed over to DR. The Server's IP has been updated, but the Cluster hasn't yet.
34
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
-
35
+ # Change Cluster IP.
36
+ # Verify step if running manually. Comment out if automated.
37
+ # Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
44
38
$new_ip = $Cluster_IP_DR
45
39
$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
-
40
+ # Subnet mask will not change after the Zerto failover
41
+ # $new_subnet_mask = "255.255.255.0" #need to determine this info after Zerto failover
42
+ $parameter1 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name , Address, $new_ip
43
+ # Subnet mask will not change after the Zerto failover
44
+ # $parameter2 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,SubnetMask,$new_subnet_mask
45
+ $parameters = $parameter1 # ,$parameter2
46
+ # Change the IPs.
47
+ $parameters | Set-ClusterParameter
48
+
49
+ # This step would happen once after the changes
50
+ Stop-ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
51
+ Start-ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
52
+
53
+ # Change AG Listener IP.
54
+ # Verify step if running manually. Comment out if automated.
55
+ # Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
56
+ $new_ip = $Listener_IP_DR
57
+ $Current_IP_Cluster_Resource_Name = Get-ClusterResource - Name $listener_resource_name
58
+ # Subnet mask will not change after the Zerto failover
59
+ # $new_subnet_mask = "255.255.255.0" #need to determine this info after Zerto failover
50
60
$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
61
+ # Subnet mask will not change after the Zerto failover
52
62
# $parameter2 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,SubnetMask,$new_subnet_mask
53
63
$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
-
64
+ # Change the IPs.
65
+ $parameters | Set-ClusterParameter
59
66
60
67
# 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
68
+ Stop-ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
69
+ Start -ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
70
+ Start-ClusterResource $AG_resource_name
64
71
}
65
72
66
73
ElseIf ($currentIP -match $Server_IP_Prod -and $Current_Cluster_ipaddress -match $Cluster_IP_DR )
67
74
{
68
75
# We've failed back to PROD. The Server's IP has been updated, but the Cluster hasn't yet.
69
76
70
- # Verify
71
- Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
72
-
73
- $new_ip = $Cluster_IP_DR
77
+ # Change Cluster IP.
78
+ # Verify step if running manually. Comment out if automated.
79
+ # Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
80
+ $new_ip = $Cluster_IP_Prod
74
81
$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
-
82
+ # Subnet mask will not change after the Zerto failover
83
+ # $new_subnet_mask = "255.255.255.0" #need to determine this info after Zerto failover
79
84
$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
85
+ # Subnet mask will not change after the Zerto failover
81
86
# $parameter2 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,SubnetMask,$new_subnet_mask
82
87
$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
+ # Change the IPs.
89
+ $parameters | Set-ClusterParameter
90
+
91
+ # This step would happen once after the changes
92
+ Stop-ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
93
+ Start-ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
94
+
95
+ # Change AG Listener IP.
96
+ # Verify step if running manually. Comment out if automated.
97
+ # Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
98
+ $new_ip = $Listener_IP_Prod
99
+ $Current_IP_Cluster_Resource_Name = Get-ClusterResource - Name $listener_resource_name
100
+ # Subnet mask will not change after the Zerto failover
101
+ # $new_subnet_mask = "255.255.255.0" #need to determine this info after Zerto failover
102
+ $parameter1 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name , Address, $new_ip
103
+ # Subnet mask will not change after the Zerto failover
104
+ # $parameter2 = New-Object Microsoft.FailoverClusters.PowerShell.ClusterParameter $Current_IP_Cluster_Resource_Name,SubnetMask,$new_subnet_mask
105
+ $parameters = $parameter1 # ,$parameter2
106
+ # Change the IPs.
107
+ $parameters | Set-ClusterParameter
88
108
89
109
# 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
-
110
+ Stop-ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
111
+ Start-ClusterResource $cluster_resource_name - ErrorAction SilentlyContinue
112
+ Start-ClusterResource $AG_resource_name
94
113
95
114
}
96
115
97
- # Verify
98
- Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
116
+ # Verify step if running manually. Comment out if automated.
117
+ # Get-ClusterResource $cluster_resource_name | Get-ClusterParameter
118
+
119
+ # This next block doesn't work if the AG can't come online. Leaving it here for future reference only.
120
+ # import-module sqlps
121
+ # Add new IP for Zerto destination to AG Listener before the failover
122
+ # this next step should only need to be done once.
123
+ # Add-SqlAvailabilityGroupListenerStaticIp -Path "SQLSERVER:\SQL\localhost\DEFAULT\AvailabilityGroups\SCRSQL\AvailabilityGroupListeners\scrsqlp01vip" -StaticIp "10.35.135.164/255.255.255.0" -Script
124
+
0 commit comments