From 95c50edee2ed5db874b31a2ea8484acf527b3775 Mon Sep 17 00:00:00 2001 From: Alexander Nosov Date: Wed, 9 Dec 2020 18:01:47 -0800 Subject: [PATCH] Updated Arcee migration script --- .../azure-arc-enabled-sql-server/README.md | 1 + .../migrate-to-azure-arc-data.ps1 | 39 ++++++++++++------- .../ahb-usage-in-subscription.ps1 | 23 ++++++++++- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/samples/manage/azure-arc-enabled-sql-server/README.md b/samples/manage/azure-arc-enabled-sql-server/README.md index 763e6b7769..b0aa6a5f51 100644 --- a/samples/manage/azure-arc-enabled-sql-server/README.md +++ b/samples/manage/azure-arc-enabled-sql-server/README.md @@ -17,6 +17,7 @@ Use the following steps to migrate your existing SQL Server - Azure Arc resource ```console curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/migrate-to-azure-arc-data.ps1 -o migrate-to-azure-arc-data.ps1 ``` + 3. Run the script. ```console diff --git a/samples/manage/azure-arc-enabled-sql-server/migrate-to-azure-arc-data.ps1 b/samples/manage/azure-arc-enabled-sql-server/migrate-to-azure-arc-data.ps1 index 10a3b0d686..a4521a1d4b 100644 --- a/samples/manage/azure-arc-enabled-sql-server/migrate-to-azure-arc-data.ps1 +++ b/samples/manage/azure-arc-enabled-sql-server/migrate-to-azure-arc-data.ps1 @@ -1,18 +1,18 @@ -# ---------------------------------------------------------------------------------- -# -# Copyright Microsoft Corporation -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # --------------------------------------------------------------------------------- # -# Sample script for migrating the existing SQL Server - Azure Arc resources from Microsoft.AzureData namespace to Microsoft.AzureArcData namespace +# Sample script for migrating the existing SQL Server - Azure Arc resources from Microsoft.AzureData namespace to Microsoft.AzureArcData namespace # within a single Resource Group # @@ -20,6 +20,18 @@ $ResourceGroup=read-host -Prompt "Enter Resource Group Name" $SqlArcResources = Get-AzResource -ExpandProperties -ResourceType Microsoft.AzureData/sqlServerInstances -ResourceGroupName $ResourceGroup foreach ($r in $SqlArcResources) { + Write-Host ("Migrating resource: {0}" -f $r.Name) + + if ( ! ($r.Properties.containerResourceId -match "Microsoft.HybridCompute/machines") ) { + $arcResource = Get-AzResource -ResourceType Microsoft.HybridCompute/machines -Name $r.Properties.containerResourceId + if($null -eq $arcResource) { + Write-Warning ("Could not locate the Machine - Azure Arc resource associated with this SQL Server Instance. You should manually un-register and re-register this instance.") + continue + } else { + $r.Properties.containerResourceId = $arcResource.ResourceId + } + } + if( $null -ne $r.Properties.tcpPorts ){ Write-Warning "The property `"tcpPorts`" has been renamed to `"tcpStaticPorts`". The property name will be updated during resource migration." $r.Properties | Add-Member -MemberType NoteProperty -Name "tcpStaticPorts" -Value $r.Properties.tcpPorts @@ -36,4 +48,3 @@ foreach ($r in $SqlArcResources) { } Write-Host "Namespace migration completed for SQL Server - Azure Arc resources." - diff --git a/samples/manage/azure-hybrid-benefit/ahb-usage-in-subscription.ps1 b/samples/manage/azure-hybrid-benefit/ahb-usage-in-subscription.ps1 index 7825887f46..3694ec3c6c 100644 --- a/samples/manage/azure-hybrid-benefit/ahb-usage-in-subscription.ps1 +++ b/samples/manage/azure-hybrid-benefit/ahb-usage-in-subscription.ps1 @@ -1,5 +1,24 @@ -# This scripts calculates the AHB usage by all the SQL resources in a specific subscription -# based on the selected Azure Hybrid Benefit option +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# --------------------------------------------------------------------------------- +# +# This script calculates the usage of different types of SQL Server licenses by the SQL resources +# in the specific subscriptions. +# +# NOTE: +# 1. The script requires a .csv file with the list of subscriptions. Use Export-Csv comlet to create the file. +# 2. SQL Database resources that use the DTU based business model are excluded. +# # Set the subscription Id $SubcriptionId = read-host -Prompt "Enter Subscription ID"