Skip to content

Commit

Permalink
Merge pull request Azure-Samples#284 from msebolt/azurecli-update-pr5
Browse files Browse the repository at this point in the history
set of revisions
  • Loading branch information
dbradish-microsoft authored Mar 30, 2020
2 parents af98725 + e92ead8 commit 13dcc85
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 674 deletions.
51 changes: 24 additions & 27 deletions sql-database/backup-database/backup-database.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
#!/bin/bash
location="East US"
randomIdentifier=random123

$subscription = "<subscriptionId>" # add subscription here
$location = "East US"
resource=resource-$randomIdentifier
server=server-$randomIdentifier
database=database-$randomIdentifier
storage=storage$randomIdentifier
container=container-$randomIdentifier

$randomIdentifier = $(Get-Random)
bacpac=backup.bacpac

$resourceGroup = "resource-$randomIdentifier"
$server = "server-$randomIdentifier"
$database = "database-$randomIdentifier"
$storage = "storage$randomIdentifier"
$container = "container-$randomIdentifier"
login=sampleLogin
password=samplePassword123!

$bacpac = "backup.bacpac"
echo "Using resource group $resource with login: $login, password: $password..."

$login = "sampleLogin"
$password = "samplePassword123!"
echo "Creating resource group $resource..."
az group create --name $resource --location "$location"

echo "Using resource group $($resourceGroup) with login: $($login), password: $($password)..."
echo "Creating $storage..."
az storage account create --name $storage --resource-group $resource --location "$location" --sku Standard_LRS

echo "Creating resource groups..."
az group create --name $resourceGroup --location $location

echo "Creating $($storage)..."
az storage account create --name $storage --resource-group $resourceGroup --location $location --sku Standard_LRS

echo "Creating $($container) on $($storage)..."
$key = az storage account keys list --account-name $storage --resource-group $resourceGroup -o json --query [0].value
echo "Creating $container on $storage..."
key=$(az storage account keys list --account-name $storage --resource-group $resource -o json --query [0].value | tr -d '"')
az storage container create --name $container --account-key $key --account-name $storage

echo "Creating $($server)..."
az sql server create --name $server --resource-group $resourceGroup --location $location --admin-user $login --admin-password $password
az sql server firewall-rule create --resource-group $resourceGroup --server $server --name AllowAzureServices --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
echo "Creating $server..."
az sql server create --name $server --resource-group $resource --location "$location" --admin-user $login --admin-password $password
az sql server firewall-rule create --resource-group $resource --server $server --name AllowAzureServices --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0

echo "Creating $($database)..."
az sql db create --name $database --resource-group $resourceGroup --server $server --edition GeneralPurpose --sample-name AdventureWorksLT
echo "Creating $database..."
az sql db create --name $database --resource-group $resource --server $server --edition GeneralPurpose --sample-name AdventureWorksLT

echo "Backing up $($database)..."
az sql db export --admin-password $password --admin-user $login --storage-key $key --storage-key-type StorageAccessKey --storage-uri "https://$storage.blob.core.windows.net/$container/$bacpac" --name $database --resource-group $resourceGroup --server $server
echo "Backing up $database..."
az sql db export --admin-password $password --admin-user $login --storage-key $key --storage-key-type StorageAccessKey --storage-uri "https://$storage.blob.core.windows.net/$container/$bacpac" --name $database --resource-group $resource --server $server
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
#!/bin/bash
location="East US"
randomIdentifier=random123

$subscription = "<subscriptionId>" # add subscription here
$location = "East US"
resource="resource-$randomIdentifier"
server="server-$randomIdentifier"
database="database-$randomIdentifier"

$randomIdentifier = $(Get-Random)
targetResource="targetResource-$randomIdentifier"
targetLocation="West US"
targetServer="targetServer-$randomIdentifier"
targetDatabase="targetDatabase-$randomIdentifier"

$resourceGroup = "resource-$randomIdentifier"
$server = "server-$randomIdentifier"
$database = "database-$randomIdentifier"
login="sampleLogin"
password="samplePassword123!"

$targetResourceGroup = "targetResource-$randomIdentifier"
$targetLocation = "West US"
$targetServer = "targetServer-$randomIdentifier"
$targetDatabase = "targetDatabase-$randomIdentifier"
echo "Using resource group $resourceGroup with login: $login, password: $password..."

$login = "sampleLogin"
$password = "samplePassword123!"
echo "Creating $resource and $targetResource..."
az group create --name $resource --location "$location"
az group create --name $targetResource --location "$targetLocation"

echo "Using resource group $($resourceGroup) with login: $($login), password: $($password)..."
echo "Creating $server in $location and $targetServer in $targetLocation..."
az sql server create --name $server --resource-group $resource --location "$location" --admin-user $login --admin-password $password
az sql server create --name $targetServer --resource-group $targetResource --location "$targetLocation" --admin-user $login --admin-password $password

echo "Creating $($resourceGroup) (and $($targetResourceGroup))..."
az group create --name $resourceGroup --location $location
az group create --name $targetResourceGroup --location $targetLocation
echo "Creating $database on $server..."
az sql db create --name $database --resource-group $resource --server $server --service-objective S0

echo "Creating $($server) in $($location) (and $($targetServer) in $($targetLocation))..."
az sql server create --name $server --resource-group $resourceGroup --location $location --admin-user $login --admin-password $password
az sql server create --name $targetServer --resource-group $targetResourceGroup --location $targetLocation --admin-user $login --admin-password $password

echo "Creating $($database) on $($server)..."
az sql db create --name $database --resource-group $resourceGroup --server $server --service-objective S0

echo "Copying $($database) (on $($server)) to $($targetDatabase) (on $($targetServer))..."
az sql db copy --dest-name $targetDatabase --dest-resource-group $targetResourceGroup --dest-server $targetServer --name $database --resource-group $resourceGroup --server $server
echo "Copying $database on $server to $targetDatabase on $targetServer..."
az sql db copy --dest-name $targetDatabase --dest-resource-group $targetResource --dest-server $targetServer --name $database --resource-group $resource --server $server
Original file line number Diff line number Diff line change
@@ -1,57 +1,25 @@
#!/bin/bash
location="East US"
randomIdentifier=random123

# set execution context (if necessary)
az account set --subscription <replace with your subscription name or id>
resource="resource-$randomIdentifier"
server="server-$randomIdentifier"
database="database-$randomIdentifier"

# Set the resource group name and location for your server
resourceGroupName=myResourceGroup-$RANDOM
location=westus2
login="sampleLogin"
password="samplePassword123!"

# Set an admin login and password for your database
adminlogin=ServerAdmin
password=`openssl rand -base64 16`
# password=<EnterYourComplexPasswordHere1>
startIP=0.0.0.0
endIP=0.0.0.0

# The logical server name has to be unique in the system
servername=server-$RANDOM
echo "Creating $resource..."
az group create --name $resource --location "$location"

# The ip address range that you want to allow to access your DB
startip=0.0.0.0
endip=0.0.0.0
echo "Creating $server in $location..."
az sql server create --name $server --resource-group $resource --location "$location" --admin-user $login --admin-password $password

# Create a resource group
az group create \
--name $resourceGroupName \
--location $location
echo "Configuring firewall..."
az sql server firewall-rule create --resource-group $resource --server $server -n AllowYourIp --start-ip-address $startIP --end-ip-address $endIP

# Create a logical server in the resource group
az sql server create \
--name $servername \
--resource-group $resourceGroupName \
--location $location \
--admin-user $adminlogin \
--admin-password $password

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

# Create a database in the server with zone redundancy as false
az sql db create \
--resource-group $resourceGroupName \
--server $servername \
--name mySampleDatabase \
--sample-name AdventureWorksLT \
--edition GeneralPurpose \
--family Gen4 \
--capacity 1 \
--zone-redundant false

# Zone redundancy is only supported in the premium and business critical service tiers

# Echo random password
echo $password
echo "Creating $database on $server..."
az sql db create --resource-group $resource --server $server --name $database --sample-name AdventureWorksLT --edition GeneralPurpose --family Gen4 --capacity 1 --zone-redundant false # zone redundancy is only supported on premium and business critical service tiers
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
#!/bin/bash
location="East US"
randomIdentifier=random123

$subscription = "<subscriptionId>" # add subscription here
$location = "East US"
resource="resource-$randomIdentifier"
server="server-$randomIdentifier"
database="database-$randomIdentifier"
storage="storage$randomIdentifier"

$randomIdentifier = $(Get-Random)
notification="changeto@your.email;changeto@your.email"

$resourceGroup = "resource-$randomIdentifier"
$server = "server-$randomIdentifier"
$database = "database-$randomIdentifier"
$storage = "storage$randomIdentifier"
login="sampleLogin"
password="samplePassword123!"

$notification = "changeto@your.email;changeto@your.email"
echo "Using resource group $resource with login: $login, password: $password..."

$login = "sampleLogin"
$password = "samplePassword123!"
echo "Creating $resource..."
az group create --name $resource --location "$location"

echo "Using resource group $($resourceGroup) with login: $($login), password: $($password)..."
echo "Creating $server in $location..."
az sql server create --name $server --resource-group $resource --location "$location" --admin-user $login --admin-password $password

echo "Creating $($resourceGroup)..."
az group create --name $resourceGroup --location $location
echo "Creating $database on $server..."
az sql db create --name $database --resource-group $resource --server $server --service-objective S0

echo "Creating $($server) in $($location) ..."
az sql server create --name $server --resource-group $resourceGroup --location $location --admin-user $login --admin-password $password
echo "Creating $storage..."
az storage account create --name $storage --resource-group $resource --location "$location" --sku Standard_LRS

echo "Creating $($database) on $($server)..."
az sql db create --name $database --resource-group $resourceGroup --server $server --service-objective S0
echo "Setting access policy on $storage..."
az sql db audit-policy update --name $database --resource-group $resource --server $server --state Enabled --storage-account $storage

echo "Creating $($storage)..."
az storage account create --name $storage --resource-group $resourceGroup --location $location --sku Standard_LRS

echo "Setting access policy on $($storage)..."
az sql db audit-policy update --name $database --resource-group $resourceGroup --server $server --state Enabled --storage-account $storage

echo "Setting threat detection policy on $($storage)..."
az sql db threat-policy update --email-account-admins Disabled --email-addresses $notification --name $database --resource-group $resourceGroup --server $server --state Enabled --storage-account $storage
echo "Setting threat detection policy on $storage..."
az sql db threat-policy update --email-account-admins Disabled --email-addresses $notification --name $database --resource-group $resource --server $server --state Enabled --storage-account $storage
Original file line number Diff line number Diff line change
@@ -1,61 +1,58 @@
#!/bin/bash
location="East US"
randomIdentifier=random123

$subscription = "<subscriptionId>" # add subscription here
$location = "East US"
resource="resource-$randomIdentifier"
server="sqlserver-$randomIdentifier"
pool="pool-$randomIdentifier"
database="database-$randomIdentifier"

$randomIdentifier = $(Get-Random)
failover="failover-$randomIdentifier"
failoverLocation="West US"
failoverServer="sqlsecondary-$randomIdentifier"

$resourceGroup = "resource-$randomIdentifier"
$server = "sqlserver-$randomIdentifier"
$pool = "pool-$randomIdentifier"
$database = "database-$randomIdentifier"
login="sampleLogin"
password="samplePassword123!"

$failover = "failover-$randomIdentifier"
$failoverLocation = "West US"
$failoverServer = "sqlsecondary-$randomIdentifier"
echo "Using resource group $resource with login: $login, password: $password..."

$login = "sampleLogin"
$password = "samplePassword123!"
echo "Creating $resource..."
az group create --name $resource --location "$location"

echo "Using resource group $($resourceGroup) with login: $($login), password: $($password)..."
echo "Creating $server in $location..."
az sql server create --name $server --resource-group $resource --location "$location" --admin-user $login --admin-password $password

echo "Creating $($resourceGroup)..."
az group create --name $resourceGroup --location $location
echo "Creating $database on $server..."
az sql db create --name $database --resource-group $resource --server $server --sample-name AdventureWorksLT

echo "Creating $($server) in $($location)..."
az sql server create --name $server --resource-group $resourceGroup --location $location --admin-user $login --admin-password $password
echo "Creating $pool on $server..."
az sql elastic-pool create --name $pool --resource-group $resource --server $server

echo "Creating $($database) on $($server)..."
az sql db create --name $database --resource-group $resourceGroup --server $server --sample-name AdventureWorksLT
echo "Adding $database to $pool..."
az sql db update --elastic-pool $pool --name $database --resource-group $resource --server $server

echo "Creating $($pool) on $($server)..."
az sql elastic-pool create --name $pool --resource-group $resourceGroup --server $server
echo "Creating $failoverServer in $failoverLocation..."
az sql server create --name $failoverServer --resource-group $resource --location "$failoverLocation" --admin-user $login --admin-password $password

echo "Adding $($database) to $($pool)..."
az sql db update --elastic-pool $pool --name $database --resource-group $resourceGroup --server $server
echo "Creating $pool on $failoverServer..."
az sql elastic-pool create --name $pool --resource-group $resource --server $failoverServer

echo "Creating $($failoverServer) in $($failoverLocation)..."
az sql server create --name $failoverServer --resource-group $resourceGroup --location $failoverLocation --admin-user $login --admin-password $password
echo "Creating $failover between $server and $failoverServer..."
az sql failover-group create --name $failover --partner-server $failoverServer --resource-group $resource --server $server --failover-policy Automatic --grace-period 2

echo "Creating $($pool) on $($failoverServer)..."
az sql elastic-pool create --name $pool --resource-group $resourceGroup --server $failoverServer
databaseId=$(az sql elastic-pool list-dbs --name $pool --resource-group $resource --server $server --query [0].name -o json | tr -d '"')

echo "Creating $($failover) between $($server) and $($failoverServer)..."
az sql failover-group create --name $failover --partner-server $failoverServer --resource-group $resourceGroup --server $server --failover-policy Automatic --grace-period 2
echo "Adding $database to $failover..."
az sql failover-group update --name $failover --add-db $databaseId --resource-group $resource --server $server

$databaseId = az sql elastic-pool list-dbs --name $pool --resource-group $resourceGroup --server $server --query [0].name -o json
echo "Confirming role of $failoverServer is secondary..." # note ReplicationRole property
az sql failover-group show --name $failover --resource-group $resource --server $server

echo "Adding $($database) to $($failover)..."
az sql failover-group update --name $failover --add-db $databaseId --resource-group $resourceGroup --server $server
echo "Failing over to $failoverServer..."
az sql failover-group set-primary --name $failover --resource-group $resource --server $failoverServer

echo "Confirming role of $($failoverServer) is secondary..." # note ReplicationRole property
az sql failover-group show --name $failover --resource-group $resourceGroup --server $server
echo "Confirming role of $failoverServer is now primary..." # note ReplicationRole property
az sql failover-group show --name $failover --resource-group $resource --server $server

echo "Failing over to $($failoverServer)..."
az sql failover-group set-primary --name $failover --resource-group $resourceGroup --server $failoverServer

echo "Confirming role of $($failoverServer) is now primary..." # note ReplicationRole property
az sql failover-group show --name $failover --resource-group $resourceGroup --server $server

echo "Failing back to $($server)...."
az sql failover-group set-primary --name $failover --resource-group $resourceGroup --server $server
echo "Failing back to $server...."
az sql failover-group set-primary --name $failover --resource-group $resource --server $server
Loading

0 comments on commit 13dcc85

Please sign in to comment.