Skip to content

Commit

Permalink
Merge pull request #32619 from djordje-jeremic/djordje-jeremic-manage…
Browse files Browse the repository at this point in the history
…d-instance-link-configure-how-to-scripts-patch-1

Update managed-instance-link-configure-how-to-scripts.md
  • Loading branch information
prmerger-automator[bot] authored Dec 12, 2024
2 parents bfb161a + 12b76d9 commit eb64e48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To replicate your databases, you need the following prerequisites:
- An active Azure subscription. If you don't have one, [create a free account](https://azure.microsoft.com/free/).
- [Supported version of SQL Server](managed-instance-link-feature-overview.md#prerequisites) with the required service update installed.
- Azure SQL Managed Instance. [Get started](instance-create-quickstart.md) if you don't have it.
- PowerShell module [Az.SQL 3.9.0 or higher](https://www.powershellgallery.com/packages/Az.Sql), or [Azure CLI 2.47.0 or higher](/cli/azure/install-azure-cli). Or preferably, use [Azure Cloud Shell](/azure/cloud-shell/overview) online from the web browser to run the commands, because it's always updated with the latest module versions.
- PowerShell module [Az.SQL 6.0.0 or higher](https://www.powershellgallery.com/packages/Az.Sql), or [Azure CLI 2.67.0 or higher](/cli/azure/install-azure-cli). Or preferably, use [Azure Cloud Shell](/azure/cloud-shell/overview) online from the web browser to run the commands, because it's always updated with the latest module versions.
- A properly [prepared environment](managed-instance-link-preparation.md).

Consider the following:
Expand Down Expand Up @@ -761,7 +761,7 @@ To simplify the process, sign in to the Azure portal and run the following scrip
- `<SQLServerIP>` with the IP address of your SQL Server. The provided IP address must be accessible by managed instance.

> [!NOTE]
> If you want establish a link to an availability group that already exists, then provide the IP address of the listener when supplying the `<SQLServerIP>` parameter.
> If you want establish a link to an availability group that already exists, then provide the IP address of the listener when supplying the `<SQLServerIP>` parameter. Please ensure that trust has been established between all availability group nodes and SQL Managed Instance (see [Establish trust between instances](#establish-trust-between-instances) section).

```powershell-interactive
Expand Down Expand Up @@ -799,8 +799,8 @@ $SourceIP = "TCP://" + $SQLServerIP + ":<EndpointPort>"
# Create link on managed instance. Join distributed availability group on SQL Server.
New-AzSqlInstanceLink -ResourceGroupName $ResourceGroup -InstanceName $ManagedInstanceName -Name $DAGName |
-PrimaryAvailabilityGroupName $AGNameOnSQLServer -SecondaryAvailabilityGroupName $AGNameOnSQLMI |
-TargetDatabase $DatabaseName -SourceEndpoint $SourceIP
-PartnerAvailabilityGroupName $AGNameOnSQLServer -InstanceAvailabilityGroupName $AGNameOnSQLMI |
-Database @($DatabaseName) -PartnerEndpoint $SourceIP -InstanceLinkRole Secondary
```


Expand All @@ -814,7 +814,6 @@ To simplify the process, sign in to the Azure portal and run the following scrip
- `<DatabaseName>` with the database replicated in the availability group on SQL Server.
- `<SQLServerIP>` with the IP address of your SQL Server. The provided IP address must be accessible by managed instance.


```powershell-interactive
# Run in Azure Cloud Shell (select PowerShell console)
# =============================================================================
Expand Down Expand Up @@ -851,37 +850,10 @@ $ResourceGroup = (Get-AzSqlInstance -InstanceName $ManagedInstanceName).Resource
# Build properly formatted connection endpoint
$DestinationIP = "TCP://" + $SQLServerIP + ":<EndpointPort>"
# Create Azure REST API request header
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$currentAzureContext = Get-AzContext
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azProfile)
$token = $profileClient.AcquireAccessToken($currentAzureContext.Tenant.TenantId)
$authToken = $token.AccessToken
$headers = @{ }
$headers.Add('Authorization', 'Bearer ' + $authToken)
# Build Azure REST API URI
$uri = "https://management.azure.com/subscriptions/"+$SubscriptionID+"/resourceGroups/"+$ResourceGroup+"/providers/Microsoft.Sql/managedInstances/"+$ManagedInstanceName+"/distributedAvailabilityGroups/"+$DAGName+"?api-version=2023-05-01-preview"
# Build Azure REST API request body
$body = "{
'properties': {
'Databases': [{
'databaseName': '$DatabaseName'
}
],
'PartnerEndpoint': '$DestinationIP',
'InstanceAvailabilityGroupName': '$AGNameOnSQLMI',
'PartnerAvailabilityGroupName': '$AGNameOnSQLServer',
'FailoverMode': 'Manual',
'SeedingMode': 'Automatic',
'InstanceLinkRole': 'Primary'
}}"
# Send link creation request to Azure REST API
Invoke-RestMethod -Method PUT -Headers $headers -Uri $uri -ContentType 'application/json' -Body $body
# Create link on managed instance. Join distributed availability group on SQL Server.
New-AzSqlInstanceLink -ResourceGroupName $ResourceGroup -InstanceName $ManagedInstanceName -Name $DAGName |
-PartnerAvailabilityGroupName $AGNameOnSQLServer -InstanceAvailabilityGroupName $AGNameOnSQLMI |
-Database @($DatabaseName) -PartnerEndpoint $DestinationIP -InstanceLinkRole Primary
```

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ You'll also need the following tools:

| Tool | Notes |
| --- | --- |
| [SSMS 20.2](/sql/ssms/download-sql-server-management-studio-ssms) or later | SQL Server Management Studio (SSMS) is the easiest way to use the Managed Instance link since it provides wizards that automate link setup. |
| [Az.SQL 3.9.0](https://www.powershellgallery.com/packages/Az.Sql) or later | A PowerShell module is required for manual configuration steps. |
| The latest [SSMS](/sql/ssms/download-sql-server-management-studio-ssms) | SQL Server Management Studio (SSMS) is the easiest way to use the Managed Instance link since it provides wizards that automate link setup. |
| The latest [Az.SQL](https://www.powershellgallery.com/packages/Az.Sql) or [Azure CLI](/cli/azure/install-azure-cli) | For link setup via scripts. |

> [!NOTE]
> The Managed Instance link feature is available in all public Azure regions and national or government clouds.
Expand Down

0 comments on commit eb64e48

Please sign in to comment.