I have created two Premium Azure Cache for Redis resources and set up geo replication. There is a button in the portal to failover manually.
How can I trigger this failover with Azure CLI?
I tried the az redis force-reboot --resource-group $resourceGroupName --name $redisPrimary --reboot-type $rebootType
command to no avail.
I did it in PowerShell by breaking the (geo-replication) link between de caches and then re-creating it, making sure to reverse the primary and secondary cache.
Use the provisioning state to monitor the state after deleting or creating the link:
$provisioningState = (Get-AzRedisCache -Name $cacheNamePrimary).ProvisioningState
if ($provisioningState -eq 'Succeeded') { etc.. }
One gotcha, after removing the link Remove-AzRedisCacheLink
and trying to create a new one New-AzRedisCacheLink
, an error might occur even though the provisioning state will report 'Succeeded'. Error message: Operation returned an invalid status code 'Conflict'
.
In this case I created a while loop that breaks when the New-AzRedisCacheLink
returns no error:
# Create cache link (geo-replication)
while ($true) {
$provisioningState = (Get-AzRedisCache -Name $cacheNamePrimary).ProvisioningState
if ($provisioningState -eq 'Succeeded') {
try {
New-AzRedisCacheLink -PrimaryServerName $cacheNameSecondary -SecondaryServerName $cacheNamePrimary -ErrorAction Stop
break
} catch {
Write-Output "Trying to creating cache link but received an error '$($_)'.. probably busy processing something.. retrying.."
Start-Sleep -Milliseconds 20000
}
} else {
Start-Sleep -Milliseconds 30000
Write-Output "Still waiting for cache link to be removed.. provisioning status '$provisioningState'.."
}
}