All in one solution to failover AlwaysOn Availability Groups in SQL Server.
Functions to run comprehensive health checks, failover availability groups, set AG replicas to sync / async modes. Can be combined with the Update-DbaInstance function for a fully automated patching solution.
Requires the SqlServer
module.
Optional: Install dbatools module for patching functionality.
This solution is built to be flexible. Functions can be pieced together to build a fully automated solution. Detailed documentation to core functions can be found here.
Import-Module SqlServer -Force
Import-Module .\src\SQLRoboFailover -Force
Import-Module dbatools -Force
Comprehensive health checks will be completed for each AG pre and post failover with a built in health polling mechanism.
Invoke-FailoverAllPrimaryAGsOnServer -ServerInstance <ServerName> -RunPostFailoverChecks -ScriptOnly:$false -Confirm
Set-AllSecondarySyncReplicasToAsync -ServerInstance <ServerInstance> -MaintainHAForAGs -ScriptOnly:$false -Confirm
[bool]$IsRestartReady = Test-IsRestartReady -ServerInstance <ServerInstance> -Verbose
if ($IsRestartReady){
Update-DbaInstance -ComputerName <ServerInsance> -Version <PatchVersion> -Path \\network\share
}
[bool]$IsSQLServerHealthy = Test-IsSQLServerHealthy -ServerInstance <ServerInstance> -RunExtendedAGChecks -Verbose
if ($IsSQLServerHealthy){
Set-AllSecondaryAsyncReplicasToSync -ServerInstance <ServerInstance> -ForceSingleSyncCopy -ScriptOnly:$false -Confirm
}