2

I am trying to find the replication role of Azure SQL DB (Primary or Secondary).

I used : Get-AzureRmSqlDatabase command but could not find the replication information.

Is there a different powershell command to find replication role ?

K.Pil
  • 786
  • 2
  • 10
  • 24

2 Answers2

3

The Get-AzureRMSqlDatabaseReplicationLink cmdlet replaces the Get-AzureSqlDatabaseCopy cmdlet.

It gets all geo-replication links between the specified Azure SQL Database and a resource group or AzureSQL Server.

Get-AzureRmSqlDatabaseReplicationLink -DatabaseName <databaseName> -PartnerResourceGroupName <partnerResourceGroupName> -ResourceGroupName <resourceGroupName> -ServerName <databaseServerName> | Select Role

Below is the result of the Azure PowerShell cmdlet above which get the replication role of the geo-replicated Azure SQL Databases.

enter image description here

Note:

The partnerResourceGroupName and resourceGroupName can be the same if the geo-replicated databases and server are in the same resource group as the primary.

Community
  • 1
  • 1
juvchan
  • 6,113
  • 2
  • 22
  • 35
2

you need to use the Get-AzureRmSqlDatabaseReplicationLink cmdlet. Refer to this article:
https://learn.microsoft.com/en-us/azure/sql-database/scripts/sql-database-setup-geodr-and-failover-database-powershell

$database = New-AzureRmSqlDatabase  -ResourceGroupName $primaryresourcegroupname `
    -ServerName $primaryservername `
    -DatabaseName $databasename -RequestedServiceObjectiveName "S0"

# Establish Active Geo-Replication
$database = Get-AzureRmSqlDatabase -DatabaseName $databasename -ResourceGroupName $primaryresourcegroupname -ServerName $primaryservername
$database | New-AzureRmSqlDatabaseSecondary -PartnerResourceGroupName $secondaryresourcegroupname -PartnerServerName $secondaryservername -AllowConnections "All"

# Initiate a planned failover
$database = Get-AzureRmSqlDatabase -DatabaseName $databasename -ResourceGroupName $secondaryresourcegroupname -ServerName $secondaryservername
$database | Set-AzureRmSqlDatabaseSecondary -PartnerResourceGroupName $primaryresourcegroupname -Failover

# Monitor Geo-Replication config and health after failover
$database = Get-AzureRmSqlDatabase -DatabaseName $databasename -ResourceGroupName $secondaryresourcegroupname -ServerName $secondaryservername
$database | Get-AzureRmSqlDatabaseReplicationLink -PartnerResourceGroupName $primaryresourcegroupname -PartnerServerName $primaryservername
4c74356b41
  • 69,186
  • 6
  • 100
  • 141