How to determine SQL database replication roles using the Azure PowerShell command Get-AzureRMSqlDatabase -
using azure resource manager powershell commands, there simple way tell whether database involved in geo-replication role either primary or secondary? used read status property returned get-azuresqldatabase
, , value of 0 meant database primary. however, there no corresponding property returned get-azurermsqldatabase
; still returns status column, value "online" both primary , secondary databases.
the reason need i'm trying maintain dozens of databases across multiple subscriptions , servers, , trying automate actions should taken on primary databases.
i found reasonable solution problem, making 1 call per database. commandlet get-azurermsqldatabasereplicationlink needed, 1 caveat; know i'm not supposed passing same value both resourcegroupname , partnerresourcegroupname, seems work (at least now), i'm going avoid having make 1 call per resource group in subscription.
using that, able create simple function:
function issecondarysqldatabase { # function determines whether specified database performing secondary replication role. # can use get-azurermsqldatabase command instance of [microsoft.azure.commands.sql.database.model.azuresqldatabasemodel] object. param ( [microsoft.azure.commands.sql.database.model.azuresqldatabasemodel] $sqldb ) process { $issecondary = $false; $replicationlinks = get-azurermsqldatabasereplicationlink ` -resourcegroupname $sqldb.resourcegroupname ` -servername $sqldb.servername ` -databasename $sqldb.databasename ` -partnerresourcegroupname $sqldb.resourcegroupname $replicationlinks | foreach-object -process ` { if ($_.role -ne "primary") { $issecondary = $true } } return $issecondary } }
Comments
Post a Comment