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.
Merge pull request Azure-Samples#284 from msebolt/azurecli-update-pr5
set of revisions
- Loading branch information
Showing
17 changed files
with
470 additions
and
674 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,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 |
47 changes: 22 additions & 25 deletions
47
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,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 |
66 changes: 17 additions & 49 deletions
66
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,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 |
47 changes: 22 additions & 25 deletions
47
...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,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 |
81 changes: 39 additions & 42 deletions
81
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,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 |
Oops, something went wrong.