Skip to content

Commit

Permalink
merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
markjbrown committed Jul 18, 2019
2 parents 0df1b61 + 1e11314 commit 25f15da
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--kind GlobalDocumentDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "Session" \
--enable-multiple-write-locations true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--capabilities EnableCassandra \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "ConsistentPrefix" \
--enable-multiple-write-locations true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--capabilities EnableGremlin \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "Session" \
--enable-multiple-write-locations true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--kind MongoDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "ConsistentPrefix" \
--enable-multiple-write-locations true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--capabilities EnableTable \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "Session" \
--enable-multiple-write-locations true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--kind GlobalDocumentDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "Session"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ az group create \
az cosmosdb create \
--name $accountName \
--kind GlobalDocumentDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--resource-group $resourceGroupName \
--default-consistency-level "Session"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ read -p "Press any key to add locations..."
az cosmosdb update \
--name $accountName \
--resource-group $resourceGroupName \
--locations "South Central US"=0 "North Central US"=1 "East US 2"=2 "West US 2"=3
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--locations regionName="East US" failoverPriority=2 \
--locations regionName="West US" failoverPriority=3


read -p "Press any key to change failover regions..."
Expand All @@ -39,4 +42,7 @@ read -p "Press any key to change failover regions..."
az cosmosdb update \
--name $accountName \
--resource-group $resourceGroupName \
--locations "South Central US"=3 "North Central US"=2 "East US 2"=1 "West US 2"=0
--locations regionName="South Central US" failoverPriority=3 \
--locations regionName="North Central US" failoverPriority=2 \
--locations regionName="East US" failoverPriority=1 \
--locations regionName="West US" failoverPriority=0
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ az group create \
az cosmosdb create \
--name $accountName \
--kind GlobalDocumentDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--resource-group $resourceGroupName \
--default-consistency-level "Session" \
--enable-multiple-write-locations true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--kind GlobalDocumentDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "Session"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--kind GlobalDocumentDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "Session" \
--enable-multiple-write-locations true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ az cosmosdb create \
--resource-group $resourceGroupName \
--name $accountName \
--kind MongoDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--default-consistency-level "Session" \
--enable-multiple-write-locations true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ az group create \
az cosmosdb create \
--name $accountName \
--kind GlobalDocumentDB \
--locations "South Central US"=0 "North Central US"=1 \
--locations regionName="South Central US" failoverPriority=0 \
--locations regionName="North Central US" failoverPriority=1 \
--resource-group $resourceGroupName \
--default-consistency-level "Session" \
--enable-multiple-write-locations true
Expand Down
116 changes: 116 additions & 0 deletions sql-database/failover-groups/add-single-db-to-failover-group-az-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash
# Set variables
subscriptionID=<SubscriptionID>
resourceGroupName=myResourceGroup-$RANDOM
location=SouthCentralUS
adminLogin=azureuser
password="PWD27!"+`openssl rand -base64 18`
serverName=mysqlserver-$RANDOM
databaseName=mySampleDatabase
drLocation=NorthEurope
drServerName=mysqlsecondary-$RANDOM
failoverGroupName=failovergrouptutorial-$RANDOM

# The ip address range that you want to allow access to your DB.
# Leaving at 0.0.0.0 will prevent outside-of-azure connections
startip=0.0.0.0
endip=0.0.0.0

# Print out randomized variables
echo Resource group name is $resourceGroupName
echo Passowrd is $password
echo Servername is $serverName
echo DR Server name $drServerName
echo Failover group name $failoverGroupName

# Set the subscription context for the Azure account
az account set -s $subscriptionID

# Create a resource group
echo "Creating resource group..."
az group create \
--name $resourceGroupName \
--location $location \
--tags Owner[=SQLDB-Samples]

# Create a logical server in the resource group
echo "Creating primary logical server..."
az sql server create \
--name $serverName \
--resource-group $resourceGroupName \
--location $location \
--admin-user $adminLogin \
--admin-password $password

# Configure a firewall rule for the server
echo "Configuring firewall..."
az sql server firewall-rule create \
--resource-group $resourceGroupName \
--server $serverName \
-n AllowYourIp \
--start-ip-address $startip \
--end-ip-address $endip

# Create a gen5 1vCore database in the server
echo "Creating a gen5 2 vCore database..."
az sql db create \
--resource-group $resourceGroupName \
--server $serverName \
--name $databaseName \
--sample-name AdventureWorksLT \
--edition GeneralPurpose \
--family Gen5 \
--capacity 2

# Create a secondary server in the failover region
echo "Creating a secondary logical server in the DR region..."
az sql server create \
--name $drServerName \
--resource-group $resourceGroupName \
--location $drLocation \
--admin-user $adminLogin\
--admin-password $password

# Create a failover group between the servers and add the database
echo "Creating a failover group between the two servers..."
az sql failover-group create \
--name $failoverGroupName \
--partner-server $drServerName \
--resource-group $resourceGroupName \
--server $serverName \
--failover-policy Automatic

# Verify which server is secondary
echo "Verifying which server is in the secondary role..."
az sql failover-group list \
--server $serverName \
--resource-group $resourceGroupName

# Failover to the secondary server
echo "Failing over group to the secondary server..."
az sql failover-group set-primary \
--name $failoverGroupName \
--resource-group $resourceGroupName \
--server $drServerName
echo "Successfully failed failover group over to" $drServerName

# Revert failover group back to the primary server
echo "Failing over group back to the primary server..."
az sql failover-group set-primary \
--name $failoverGroupName \
--resource-group $resourceGroupName \
--server $serverName
echo "Successfully failed failover group back to" $serverName

# Print out randomized variables
echo Resource group name is $resourceGroupName
echo Password is $password
echo Servername is $serverName
echo DR Server name $drServerName
echo Failover group name $failoverGroupName

# Clean up resources by removing the resource group
# echo "Cleaning up resources by removing the resource group..."
# az group delete \
# --name $resourceGroupName
# echo "Successfully removed resource group" $resourceGroupName

0 comments on commit 25f15da

Please sign in to comment.