Last active
March 16, 2017 08:39
-
-
Save milannankov/4c0fb4e9273da0f81e462d82076f11ab to your computer and use it in GitHub Desktop.
Code Bites: Azure SQL Server Geo-Replication With PowerShell - ASM vs. ARM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$dbUser = "tester" | |
$dbPass = "myP@ssword" | |
$primaryServerName = "serverName" | |
$primaryDbName = "dbName" | |
$resourceGroupName = "groupName" | |
$secondaryServerName = "secondary" + (Get-Random) | |
$existingDb = Get-AzureRmSqlDatabase -ServerName $primaryServerName -DatabaseName $primaryDbName ` | |
-ResourceGroupName $resourceGroupName | |
# Create secondary server | |
$securePass = ConvertTo-SecureString -String $dbPass -AsPlainText -Force | |
$dbCredentials = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $dbUser, $securePass | |
$serverSecondary = New-AzureRmSqlServer -ServerName $secondaryServerName ` | |
-ResourceGroupName $existingDb.ResourceGroupName -Location "West Europe" ` | |
-SqlAdministratorCredentials $dbCredentials | |
# Activate geo-replication | |
$existingDb | New-AzureRmSqlDatabaseSecondary ` | |
-PartnerServerName $secondaryServerName ` | |
-PartnerResourceGroupName $existingDb.ResourceGroupName | |
# To allow connections to your secondary DB just add -AllowConnections All |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$dbUser = "tester" | |
$dbPass = "myP@ssword" | |
$primaryServerName = "serverName" | |
$primaryDbName = "dbName" | |
$secondaryServerName = "secondary" + (Get-Random) | |
$existingDb = Get-AzureSqlDatabase -ServerName $primaryServerName -DatabaseName $primaryDbName | |
# Create secondary server | |
$serverSecondary = New-AzureSqlDatabaseServer -Location "West Europe" ` | |
-AdministratorLogin "$dbUser" ` | |
-AdministratorLoginPassword "$dbPass" ` | |
-Version "12.0" | |
# Activate geo-replication | |
Start-AzureSqlDatabaseCopy -ServerName $primaryServerName -DatabaseName $primaryDbName ` | |
-PartnerServer $serverSecondary.ServerName ` | |
-ContinuousCopy -OfflineSecondary | |
# To allow connections to your secondary DB just remove OfflineSecondary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment