|
| 1 | +--- |
| 2 | +title: CLI example- Failover group - Azure SQL Database managed instance |
| 3 | +description: Azure CLI example script to create an Azure SQL Database managed instance, add it to a failover group, and test failover. |
| 4 | +services: sql-database |
| 5 | +ms.service: sql-database |
| 6 | +ms.subservice: high-availability |
| 7 | +ms.custom: |
| 8 | +ms.devlang: azurecli |
| 9 | +ms.topic: sample |
| 10 | +author: MashaMSFT |
| 11 | +ms.author: mathoma |
| 12 | +ms.reviewer: carlrab |
| 13 | +ms.date: 07/16/2019 |
| 14 | +--- |
| 15 | +# Use CLI to add an Azure SQL Database managed instance to a failover group |
| 16 | + |
| 17 | +This PowerShell script example creates two managed instances, adds them to a failover group, and then tests failover from the primary managed instance to the secondary managed instance. |
| 18 | + |
| 19 | +[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)] |
| 20 | + |
| 21 | +[!INCLUDE [cloud-shell-try-it.md](../../../includes/cloud-shell-try-it.md)] |
| 22 | + |
| 23 | +If you choose to install and use the CLI locally, this article requires that you are running the Azure CLI version 2.0 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install the Azure CLI](/cli/azure/install-azure-cli). |
| 24 | + |
| 25 | +## Sample scripts |
| 26 | + |
| 27 | +[!code-azurecli-interactive[main](../../../cli_scripts/sql-database/failover-groups/add-managed-instance-to-failover-group-az-cli.sh "Add managed instance to a failover group")] |
| 28 | + |
| 29 | +## Clean up deployment |
| 30 | + |
| 31 | +Use the following command to remove the resource group and all resources associated with it. You will need to remove the resource group twice. Removing the resource group the first time will remove the managed instance and virtual clusters but will then fail with the error message `az group delete : Long running operation failed with status 'Conflict'.`. Run the az group delete command a second time to remove any residual resources as well as the resource group. |
| 32 | + |
| 33 | +```azurecli-interactive |
| 34 | +az group delete --name $resourceGroupName |
| 35 | +``` |
| 36 | + |
| 37 | +## Script explanation |
| 38 | + |
| 39 | +This script uses the following commands. Each command in the table links to command specific documentation. |
| 40 | + |
| 41 | +| Command | Notes | |
| 42 | +|---|---| |
| 43 | +| [az group create](/cli/azure/group#az-group-create) | Creates a resource group in which all resources are stored. | |
| 44 | +| [az network vnet create](/cli/azure/network/vnet#az-network-vnet-create) | Creates a virtual network. | |
| 45 | +| [az network vnet subnet create](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-create) | Adds a subnet configuration to a virtual network. | |
| 46 | +| [az network vnet show](/cli/azure/network/vnet#az-network-vnet-show) | Gets a virtual network in a resource group. | |
| 47 | +| [az network vnet subnet show](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-show) | Gets a subnet in a virtual network. | |
| 48 | +| [az network nsg create](/cli/azure/network/nsg#az-network-nsg-create) | Creates a network security group. | |
| 49 | +| [az network route-table create](/cli/azure/network/route-table#az-network-route-table-create) | Creates a route table. | |
| 50 | +| [az network vnet subnet update](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-update) | Updates a subnet configuration for a virtual network. | |
| 51 | +| [az network vnet update](/cli/azure/network/vnet#az-network-vnet-update) | Updates a virtual network. | |
| 52 | +| [az network nsg show](/cli/azure/network/nsg#az-network-nsg-show) | Gets a network security group. | |
| 53 | +| [az network nsg rule create](/cli/azure/network/nsg/rule#az-network-nsg-rule-create)| Adds a network security rule configuration to a network security group. | |
| 54 | +| [az network nsg rule update](/cli/azure/network/nsg#az-network-nsg-update) | Updates a network security group. | |
| 55 | +| [az network route-table route create](/cli/azure/network/route-table/route#az-network-route-table-route-create) | Adds a route to a route table. | |
| 56 | +| [az network route-table update](/cli/azure/network/route-table#az-network-route-table-update) | Updates a route table. | |
| 57 | +| [az sql mi create](/cli/azure/sql/mi#az-sql-mi-create) | Creates an Azure SQL Database managed instance. | |
| 58 | +| [az sql mi show](/cli/azure/sql/mi#az-sql-mi-show)| Returns information about Azure SQL Managed Database Instance. | |
| 59 | +| [az network public-ip create](/cli/azure/network/public-ip#az-network-public-ip-create) | Creates a public IP address. | |
| 60 | +| [az network vnet-gateway create](/cli/azure/network/vnet-gateway#az-network-vnet-gateway-create) | Creates a Virtual Network Gateway | |
| 61 | +| [az sql instance-failover-group create](/cli/azure/sql/instance-failover-group#az-sql-instance-failover-group-create) | Creates a new Azure SQL Database managed instance failover group. | |
| 62 | +| [az sql instance-failover-group show](/cli/azure/sql/instance-failover-group#az-sql-instance-failover-group-show) | Gets or lists managed instance failover groups.| |
| 63 | +| [az sql instance-failover-group set-primary](/cli/azure/sql/instance-failover-group#az-sql-instance-failover-group-set-primary) | Executes a failover of a managed instance failover group. | |
| 64 | +| [az group delete](/cli/azure/vm/extension#az-vm-extension-set) | Deletes a resource group including all nested resources. | |
| 65 | + |
| 66 | +## Next steps |
| 67 | + |
| 68 | +For more information on the Azure CLI, see [Azure CLI documentation](https://docs.microsoft.com/cli/azure). |
| 69 | + |
| 70 | +Additional SQL Database CLI script samples can be found in the [Azure SQL Database documentation](../sql-database-cli-samples.md). |
0 commit comments