forked from Azure-Samples/azure-cli-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew Sebolt (Aquent LLC)
committed
Mar 24, 2020
1 parent
12ccd3e
commit e92ead8
Showing
17 changed files
with
390 additions
and
388 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
#!/bin/bash | ||
$location = "East US" | ||
$randomIdentifier = $(Get-Random) | ||
location="East US" | ||
randomIdentifier=random123 | ||
|
||
$resource = "resource-$randomIdentifier" | ||
$server = "server-$randomIdentifier" | ||
$database = "database-$randomIdentifier" | ||
$storage = "storage$randomIdentifier" | ||
$container = "container-$randomIdentifier" | ||
resource=resource-$randomIdentifier | ||
server=server-$randomIdentifier | ||
database=database-$randomIdentifier | ||
storage=storage$randomIdentifier | ||
container=container-$randomIdentifier | ||
|
||
$bacpac = "backup.bacpac" | ||
bacpac=backup.bacpac | ||
|
||
$login = "sampleLogin" | ||
$password = "samplePassword123!" | ||
login=sampleLogin | ||
password=samplePassword123! | ||
|
||
echo "Using resource group $($resource) with login: $($login), password: $($password)..." | ||
echo "Using resource group $resource with login: $login, password: $password..." | ||
|
||
echo "Creating resource groups..." | ||
az group create --name $resource --location $location | ||
echo "Creating resource group $resource..." | ||
az group create --name $resource --location "$location" | ||
|
||
echo "Creating $($storage)..." | ||
az storage account create --name $storage --resource-group $resource --location $location --sku Standard_LRS | ||
echo "Creating $storage..." | ||
az storage account create --name $storage --resource-group $resource --location "$location" --sku Standard_LRS | ||
|
||
echo "Creating $($container) on $($storage)..." | ||
$key = az storage account keys list --account-name $storage --resource-group $resource -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 $resource --location $location --admin-user $login --admin-password $password | ||
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)..." | ||
echo "Creating $database..." | ||
az sql db create --name $database --resource-group $resource --server $server --edition GeneralPurpose --sample-name AdventureWorksLT | ||
|
||
echo "Backing up $($database)..." | ||
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 |
40 changes: 20 additions & 20 deletions
40
sql-database/copy-database-to-new-server/copy-database-to-new-server.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
#!/bin/bash | ||
$location = "East US" | ||
$randomIdentifier = $(Get-Random) | ||
location="East US" | ||
randomIdentifier=random123 | ||
|
||
$resource = "resource-$randomIdentifier" | ||
$server = "server-$randomIdentifier" | ||
$database = "database-$randomIdentifier" | ||
resource="resource-$randomIdentifier" | ||
server="server-$randomIdentifier" | ||
database="database-$randomIdentifier" | ||
|
||
$targetResource = "targetResource-$randomIdentifier" | ||
$targetLocation = "West US" | ||
$targetServer = "targetServer-$randomIdentifier" | ||
$targetDatabase = "targetDatabase-$randomIdentifier" | ||
targetResource="targetResource-$randomIdentifier" | ||
targetLocation="West US" | ||
targetServer="targetServer-$randomIdentifier" | ||
targetDatabase="targetDatabase-$randomIdentifier" | ||
|
||
$login = "sampleLogin" | ||
$password = "samplePassword123!" | ||
login="sampleLogin" | ||
password="samplePassword123!" | ||
|
||
echo "Using resource group $($resourceGroup) with login: $($login), password: $($password)..." | ||
echo "Using resource group $resourceGroup with login: $login, password: $password..." | ||
|
||
echo "Creating $($resource) (and $($targetResource))..." | ||
az group create --name $resource --location $location | ||
az group create --name $targetResource --location $targetLocation | ||
echo "Creating $resource and $targetResource..." | ||
az group create --name $resource --location "$location" | ||
az group create --name $targetResource --location "$targetLocation" | ||
|
||
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 $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 $($database) on $($server)..." | ||
echo "Creating $database on $server..." | ||
az sql db create --name $database --resource-group $resource --server $server --service-objective S0 | ||
|
||
echo "Copying $($database) (on $($server)) to $($targetDatabase) (on $($targetServer))..." | ||
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 |
28 changes: 14 additions & 14 deletions
28
sql-database/create-and-configure-database/create-and-configure-database.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
#!/bin/bash | ||
$location = "East US" | ||
$randomIdentifier = $(Get-Random) | ||
location="East US" | ||
randomIdentifier=random123 | ||
|
||
$resource = "resource-$randomIdentifier" | ||
$server = "server-$randomIdentifier" | ||
$database = "database-$randomIdentifier" | ||
resource="resource-$randomIdentifier" | ||
server="server-$randomIdentifier" | ||
database="database-$randomIdentifier" | ||
|
||
$login = "sampleLogin" | ||
$password = "samplePassword123!" | ||
login="sampleLogin" | ||
password="samplePassword123!" | ||
|
||
$startIP=0.0.0.0 | ||
$endIP=0.0.0.0 | ||
startIP=0.0.0.0 | ||
endIP=0.0.0.0 | ||
|
||
echo "Creating $($resource)..." | ||
az group create --name $resource --location $location | ||
echo "Creating $resource..." | ||
az group create --name $resource --location "$location" | ||
|
||
echo "Creating $($server) in $($location)..." | ||
az sql server create --name $server --resource-group $resource --location $location --admin-user $login --admin-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 "Configuring firewall..." | ||
az sql server firewall-rule create --resource-group $resource --server $server -n AllowYourIp --start-ip-address $startIP --end-ip-address $endIP | ||
|
||
echo "Creating $($database) on $($server)..." | ||
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 |
38 changes: 19 additions & 19 deletions
38
...database/database-auditing-and-threat-detection/database-auditing-and-threat-detection.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
#!/bin/bash | ||
$location = "East US" | ||
$randomIdentifier = $(Get-Random) | ||
location="East US" | ||
randomIdentifier=random123 | ||
|
||
$resource = "resource-$randomIdentifier" | ||
$server = "server-$randomIdentifier" | ||
$database = "database-$randomIdentifier" | ||
$storage = "storage$randomIdentifier" | ||
resource="resource-$randomIdentifier" | ||
server="server-$randomIdentifier" | ||
database="database-$randomIdentifier" | ||
storage="storage$randomIdentifier" | ||
|
||
$notification = "changeto@your.email;changeto@your.email" | ||
notification="changeto@your.email;changeto@your.email" | ||
|
||
$login = "sampleLogin" | ||
$password = "samplePassword123!" | ||
login="sampleLogin" | ||
password="samplePassword123!" | ||
|
||
echo "Using resource group $($resource) with login: $($login), password: $($password)..." | ||
echo "Using resource group $resource with login: $login, password: $password..." | ||
|
||
echo "Creating $($resource)..." | ||
az group create --name $resource --location $location | ||
echo "Creating $resource..." | ||
az group create --name $resource --location "$location" | ||
|
||
echo "Creating $($server) in $($location)..." | ||
az sql server create --name $server --resource-group $resource --location $location --admin-user $login --admin-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 $($database) on $($server)..." | ||
echo "Creating $database on $server..." | ||
az sql db create --name $database --resource-group $resource --server $server --service-objective S0 | ||
|
||
echo "Creating $($storage)..." | ||
az storage account create --name $storage --resource-group $resource --location $location --sku Standard_LRS | ||
echo "Creating $storage..." | ||
az storage account create --name $storage --resource-group $resource --location "$location" --sku Standard_LRS | ||
|
||
echo "Setting access policy on $($storage)..." | ||
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 "Setting threat detection policy on $($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 |
58 changes: 29 additions & 29 deletions
58
sql-database/failover-groups/add-elastic-pool-to-failover-group-az-cli.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
#!/bin/bash | ||
$location = "East US" | ||
$randomIdentifier = $(Get-Random) | ||
location="East US" | ||
randomIdentifier=random123 | ||
|
||
$resource = "resource-$randomIdentifier" | ||
$server = "sqlserver-$randomIdentifier" | ||
$pool = "pool-$randomIdentifier" | ||
$database = "database-$randomIdentifier" | ||
resource="resource-$randomIdentifier" | ||
server="sqlserver-$randomIdentifier" | ||
pool="pool-$randomIdentifier" | ||
database="database-$randomIdentifier" | ||
|
||
$failover = "failover-$randomIdentifier" | ||
$failoverLocation = "West US" | ||
$failoverServer = "sqlsecondary-$randomIdentifier" | ||
failover="failover-$randomIdentifier" | ||
failoverLocation="West US" | ||
failoverServer="sqlsecondary-$randomIdentifier" | ||
|
||
$login = "sampleLogin" | ||
$password = "samplePassword123!" | ||
login="sampleLogin" | ||
password="samplePassword123!" | ||
|
||
echo "Using resource group $($resource) with login: $($login), password: $($password)..." | ||
echo "Using resource group $resource with login: $login, password: $password..." | ||
|
||
echo "Creating $($resource)..." | ||
az group create --name $resource --location $location | ||
echo "Creating $resource..." | ||
az group create --name $resource --location "$location" | ||
|
||
echo "Creating $($server) in $($location)..." | ||
az sql server create --name $server --resource-group $resource --location $location --admin-user $login --admin-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 $($database) on $($server)..." | ||
echo "Creating $database on $server..." | ||
az sql db create --name $database --resource-group $resource --server $server --sample-name AdventureWorksLT | ||
|
||
echo "Creating $($pool) on $($server)..." | ||
echo "Creating $pool on $server..." | ||
az sql elastic-pool create --name $pool --resource-group $resource --server $server | ||
|
||
echo "Adding $($database) to $($pool)..." | ||
echo "Adding $database to $pool..." | ||
az sql db update --elastic-pool $pool --name $database --resource-group $resource --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 "Creating $failoverServer in $failoverLocation..." | ||
az sql server create --name $failoverServer --resource-group $resource --location "$failoverLocation" --admin-user $login --admin-password $password | ||
|
||
echo "Creating $($pool) on $($failoverServer)..." | ||
echo "Creating $pool on $failoverServer..." | ||
az sql elastic-pool create --name $pool --resource-group $resource --server $failoverServer | ||
|
||
echo "Creating $($failover) between $($server) and $($failoverServer)..." | ||
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 | ||
|
||
$databaseId = az sql elastic-pool list-dbs --name $pool --resource-group $resource --server $server --query [0].name -o json | ||
databaseId=$(az sql elastic-pool list-dbs --name $pool --resource-group $resource --server $server --query [0].name -o json | tr -d '"') | ||
|
||
echo "Adding $($database) to $($failover)..." | ||
echo "Adding $database to $failover..." | ||
az sql failover-group update --name $failover --add-db $databaseId --resource-group $resource --server $server | ||
|
||
echo "Confirming role of $($failoverServer) is secondary..." # note ReplicationRole property | ||
echo "Confirming role of $failoverServer is secondary..." # note ReplicationRole property | ||
az sql failover-group show --name $failover --resource-group $resource --server $server | ||
|
||
echo "Failing over to $($failoverServer)..." | ||
echo "Failing over to $failoverServer..." | ||
az sql failover-group set-primary --name $failover --resource-group $resource --server $failoverServer | ||
|
||
echo "Confirming role of $($failoverServer) is now primary..." # note ReplicationRole property | ||
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 back to $($server)...." | ||
echo "Failing back to $server...." | ||
az sql failover-group set-primary --name $failover --resource-group $resource --server $server |
Oops, something went wrong.