# ****************************************************** # * # * Name: powershell-4-geo-replication.sql # * # * Design Phase: # * Author: John Miner # * Date: 11-29-2016 # * Purpose: Demonstrate Active Geo Replication # * for Azure SQL database. # * # ****************************************************** # # Azure Subscriptions # # Prompts you for azure credentials Add-AzureRmAccount # Clear the screen Clear-Host # List my subscriptions Get-AzureRmSubscription # Pick my MSDN one Set-AzureRmContext -SubscriptionId '26efaaba-5054-4f31-b922-84ab9eff218e' <# Manually run make-prime-number-database.sql from SSMS (1 - East US) #> # # Create active geo replication (east, west) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | New-AzureRmSqlDatabaseSecondary –PartnerResourceGroupName "rg4poc2west" –PartnerServerName "sql4poc2west" -AllowConnections "All" $secondarydb # # What is the status of the link (east, west) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroup "rg4poc2west” –PartnerServerName "sql4poc2west” $secondarydb # # Create active geo replication (east, uk) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | New-AzureRmSqlDatabaseSecondary –PartnerResourceGroupName "rg4poc3uk" –PartnerServerName "sql4poc3uk" -AllowConnections "All" # # What is the status of the link (east, uk) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroup "rg4poc3uk” –PartnerServerName "sql4poc3uk” $secondarydb # # Create active geo replication (east, aus) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | New-AzureRmSqlDatabaseSecondary –PartnerResourceGroupName "rg4poc4aus" –PartnerServerName "sql4poc4aus" -AllowConnections "All" # # What is the status of the link (east, aus) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroup "rg4poc4aus” –PartnerServerName "sql4poc4aus” $secondarydb # # Create active geo replication (east, jap) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | New-AzureRmSqlDatabaseSecondary –PartnerResourceGroupName "rg4poc5jap" –PartnerServerName "sql4poc5jap" -AllowConnections "All" # # What is the status of the link (east, jap) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroup "rg4poc5jap” –PartnerServerName "sql4poc5jap” $secondarydb # # Remove the active geo replication (uk) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroupName "rg4poc3uk" –PartnerServerName "sql4poc3uk" $secondarydb | Remove-AzureRmSqlDatabaseSecondary # # Remove the active geo replication (aus) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroupName "rg4poc4aus" –PartnerServerName "sql4poc4aus" $secondarydb | Remove-AzureRmSqlDatabaseSecondary # # Remove the active geo replication (jap) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroupName "rg4poc5jap" –PartnerServerName "sql4poc5jap" $secondarydb | Remove-AzureRmSqlDatabaseSecondary # # Cause failover from east to west # $secondarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc2west" -ServerName "sql4poc2west" $primarydb = $secondarydb | Set-AzureRmSqlDatabaseSecondary -PartnerResourceGroupName "rg4poc1east" -Failover -AllowDataLoss # # Remove the active geo replication (west) # $primarydb = Get-AzureRmSqlDatabase –DatabaseName "MATH" -ResourceGroupName "rg4poc1east" -ServerName "sql4poc1east" $secondarydb = $primarydb | Get-AzureRmSqlDatabaseReplicationLink –PartnerResourceGroupName "rg4poc2west" –PartnerServerName "sql4poc2west" $secondarydb | Remove-AzureRmSqlDatabaseSecondary # # https://docs.microsoft.com/en-us/azure/sql-database/sql-database-geo-replication-overview # # https://azure.microsoft.com/en-us/regions/services/