Moving your Azure SQL Virtual Machines to a different resource group

Published Jan 15 2019 04:52 PM 491 Views
Microsoft
First published on MSDN on Feb 26, 2016
When you deal with SQL Server VMs on Azure, there are many operations that you didn’t have to do for on-premises systems.   One of the tasks I get asked as side questions when dealing with SQL issues is how to move SQL VMs to a different resource group.  It’s one of those things that you didn’t bother to plan and later found out that your VMs are in “group-1”, “group-2” etc.

Move resources to new resource group or subscription has basic steps on how to do the move.   But usually SQL Server is move involved. I”m sharing lessons learned.  For example, I have the following configuration for my AlwaysOn.







When you look at this configuration, there are a few challenges.

First of all, the AG group contains multiple resources. you can’t just move one but not the other.  You can’t just move VMs but not domain names.  if you try to move just VM, you will get errors like

Move-AzureRmResource : {"Error":{"Code":"ResourceMoveFailed","Target":null,"Message":"Resources '/subscriptions/9a4d91e7-d53a-4b70-a7c2-549a18579a9e/resourceGroups/testmove8898/providers/Microsoft.ClassicCompute/virtualMachines/testmove' could not be

moved. The tracking Id is 'fea3187d-7e67-4f69-8354-9ca5184ae9ef'","Details":[{"Code":null,"Target":"Microsoft.ClassicCompute/virtualMachines","Message":"{\"error\":{\"code\":\"NoDomainNamesToMove\",\"message\":\"Move request contains virtual machines but

not the domain names.\"}}","Details":null}]}}

At line:2 char:1

+ Move-AzureRmResource -DestinationResourceGroupName "Group-1" -Resourc ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : CloseError: (:) [Move-AzureRmResource], ErrorResponseMessageException

+ FullyQualifiedErrorId : Conflict,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.MoveAzureResourceCommand



Secondly, I got lots of duplicate names.  How do you deal with that?


Here are lessons learned from helping customers.



  1. You should always verify your subscription first.  You may have multiple subscriptions in same login and then you can’t find your resource to move.  This has led down some goose chase.

  2. Specify resource type when using Get-AzureRmResource  if you have duplicate names

  3. Move all resources (if they support the move) and their dependencies together in one move.  For example, VMs depend on domain names (or cloud service names).   You must move them together.

  4. You can move Azure classic deployment as well

  5. Not every resource supports moving resource groups. As an example, classic VNET doesn’t support moving resources.

  6. You can’t move them together if resources don’t belong to the same provider.  This is because one move request can only contain resources of only 1 provider.  For example, you can’t move storage together with VMs



Below is an example of moving above configuration from ag2000 to DataTier


#install powershell https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/
#review https://azure.microsoft.com/en-us/documentation/articles/resource-group-move-resources/

#login to Azure RM account
login-azurermaccount

#get Azure Subscription associated with this account
Get-AzureRmSubscription

# To select a default subscription for your current session
Get-AzureRmSubscription –SubscriptionName “<subscription nanme>” | Select-AzureRmSubscription

# verify your default subscription
Get-AzureRmContext

#get azure resource groups
get-azurermresourcegroup | sort-object -Property ResourceGroupName |select ResourceGroupName

#new resource group
New-AzureRmResourceGroup -Name "DataTier" -Location "South Central US"

#find all resources associated with group -1
Find-AzureRmResource  -ResourceGroupNameContains ag2000 |select ResourceGroupName,Name, ResourceType, Location



#moving multiple resource together if there are dependencies (such as domain name that a VM depends on)
$sourcegroup="ag2000"
$destgroup="DataTier"
#$vnet=Get-AzureRmResource -ResourceName ag2000 -ResourceGroupName $sourcegroup -ResourceType Microsoft.ClassicNetwork/virtualNetworks
$domainname=Get-AzureRmResource -ResourceName agdc -ResourceGroupName $sourcegroup -ResourceType Microsoft.ClassicCompute/domainNames
#$storage =Get-AzureRmResource -ResourceName ag2000 -ResourceGroupName $sourcegroup -ResourceType Microsoft.ClassicStorage/storageAccounts
$dc=Get-AzureRmResource -ResourceName agdc -ResourceGroupName $sourcegroup -ResourceType Microsoft.ClassicCompute/virtualMachines
$vm1 = Get-AzureRmResource -ResourceName agsql1 -ResourceGroupName $sourcegroup -ResourceType Microsoft.ClassicCompute/virtualMachines
$vm2 = Get-AzureRmResource -ResourceName agsql2 -ResourceGroupName $sourcegroup -ResourceType Microsoft.ClassicCompute/virtualMachines
$vm3 = Get-AzureRmResource -ResourceName "ag-sql3"  -ResourceGroupName $sourcegroup -ResourceType Microsoft.ClassicCompute/virtualMachines

Move-AzureRmResource -DestinationResourceGroupName $destgroup -ResourceId $domainname.ResourceId,$dc.ResourceId,$vm1.ResourceId,$vm2.ResourceId,$vm3.ResourceId





#verify that resources are in the new group
Find-AzureRmResource  -ResourceGroupNameContains DataTier |select ResourceGroupName,Name, ResourceType, Location











Jack Li |Senior Escalation Engineer | Microsoft SQL Server

twitter | pssdiag | Sql Nexus
%3CLINGO-SUB%20id%3D%22lingo-sub-318692%22%20slang%3D%22en-US%22%3EMoving%20your%20Azure%20SQL%20Virtual%20Machines%20to%20a%20different%20resource%20group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-318692%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Feb%2026%2C%202016%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20When%20you%20deal%20with%20SQL%20Server%20VMs%20on%20Azure%2C%20there%20are%20many%20operations%20that%20you%20didn%E2%80%99t%20have%20to%20do%20for%20on-premises%20systems.%26nbsp%3B%26nbsp%3B%20One%20of%20the%20tasks%20I%20get%20asked%20as%20side%20questions%20when%20dealing%20with%20SQL%20issues%20is%20how%20to%20move%20SQL%20VMs%20to%20a%20different%20resource%20group.%26nbsp%3B%20It%E2%80%99s%20one%20of%20those%20things%20that%20you%20didn%E2%80%99t%20bother%20to%20plan%20and%20later%20found%20out%20that%20your%20VMs%20are%20in%20%E2%80%9Cgroup-1%E2%80%9D%2C%20%E2%80%9Cgroup-2%E2%80%9D%20etc.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fresource-group-move-resources%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMove%20resources%20to%20new%20resource%20group%20or%20subscription%20%3C%2FA%3E%20has%20basic%20steps%20on%20how%20to%20do%20the%20move.%26nbsp%3B%26nbsp%3B%20But%20usually%20SQL%20Server%20is%20move%20involved.%20I%E2%80%9Dm%20sharing%20lessons%20learned.%26nbsp%3B%20For%20example%2C%20I%20have%20the%20following%20configuration%20for%20my%20AlwaysOn.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68388iB6504F14E1721D80%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20When%20you%20look%20at%20this%20configuration%2C%20there%20are%20a%20few%20challenges.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20First%20of%20all%2C%20the%20AG%20group%20contains%20multiple%20resources.%20you%20can%E2%80%99t%20just%20move%20one%20but%20not%20the%20other.%26nbsp%3B%20You%20can%E2%80%99t%20just%20move%20VMs%20but%20not%20domain%20names.%26nbsp%3B%20if%20you%20try%20to%20move%20just%20VM%2C%20you%20will%20get%20errors%20like%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Move-AzureRmResource%20%3A%20%7B%22Error%22%3A%7B%22Code%22%3A%22ResourceMoveFailed%22%2C%22Target%22%3Anull%2C%22Message%22%3A%22Resources%20'%2Fsubscriptions%2F9a4d91e7-d53a-4b70-a7c2-549a18579a9e%2FresourceGroups%2Ftestmove8898%2Fproviders%2FMicrosoft.ClassicCompute%2FvirtualMachines%2Ftestmove'%20could%20not%20be%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20moved.%20The%20tracking%20Id%20is%20'fea3187d-7e67-4f69-8354-9ca5184ae9ef'%22%2C%22Details%22%3A%5B%7B%22Code%22%3Anull%2C%22Target%22%3A%22Microsoft.ClassicCompute%2FvirtualMachines%22%2C%22Message%22%3A%22%7B%5C%22error%5C%22%3A%7B%5C%22code%5C%22%3A%5C%22NoDomainNamesToMove%5C%22%2C%5C%22message%5C%22%3A%5C%22Move%20request%20contains%20virtual%20machines%20but%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20not%20the%20domain%20names.%5C%22%7D%7D%22%2C%22Details%22%3Anull%7D%5D%7D%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20At%20line%3A2%20char%3A1%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2B%20Move-AzureRmResource%20-DestinationResourceGroupName%20%22Group-1%22%20-Resourc%20...%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2B%20CategoryInfo%20%3A%20CloseError%3A%20(%3A)%20%5BMove-AzureRmResource%5D%2C%20ErrorResponseMessageException%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2B%20FullyQualifiedErrorId%20%3A%20Conflict%2CMicrosoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.MoveAzureResourceCommand%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Secondly%2C%20I%20got%20lots%20of%20duplicate%20names.%26nbsp%3B%20How%20do%20you%20deal%20with%20that%3F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1731519105%22%20id%3D%22toc-hId-1823838402%22%3EHere%20are%20lessons%20learned%20from%20helping%20customers.%3C%2FH2%3E%3CBR%20%2F%3E%3COL%3E%3CBR%20%2F%3E%3CLI%3EYou%20should%20always%20verify%20your%20subscription%20first.%26nbsp%3B%20You%20may%20have%20multiple%20subscriptions%20in%20same%20login%20and%20then%20you%20can%E2%80%99t%20find%20your%20resource%20to%20move.%26nbsp%3B%20This%20has%20led%20down%20some%20goose%20chase.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ESpecify%20resource%20type%20when%20using%20Get-AzureRmResource%26nbsp%3B%20if%20you%20have%20duplicate%20names%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EMove%20all%20resources%20(if%20they%20support%20the%20move)%20and%20their%20dependencies%20together%20in%20one%20move.%26nbsp%3B%20For%20example%2C%20VMs%20depend%20on%20domain%20names%20(or%20cloud%20service%20names).%26nbsp%3B%26nbsp%3B%20You%20must%20move%20them%20together.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EYou%20can%20move%20Azure%20classic%20deployment%20as%20well%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ENot%20every%20resource%20supports%20moving%20resource%20groups.%20As%20an%20example%2C%20classic%20VNET%20doesn%E2%80%99t%20support%20moving%20resources.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EYou%20can%E2%80%99t%20move%20them%20together%20if%20resources%20don%E2%80%99t%20belong%20to%20the%20same%20provider.%26nbsp%3B%20This%20is%20because%20one%20move%20request%20can%20only%20contain%20resources%20of%20only%201%20provider.%26nbsp%3B%20For%20example%2C%20you%20can%E2%80%99t%20move%20storage%20together%20with%20VMs%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FOL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--820637856%22%20id%3D%22toc-hId--728318559%22%3EBelow%20is%20an%20example%20of%20moving%20above%20configuration%20from%20ag2000%20to%20DataTier%3C%2FH2%3E%3CBR%20%2F%3E%20%23install%20powershell%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fpowershell-install-configure%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fpowershell-install-configure%2F%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%23review%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fresource-group-move-resources%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fdocumentation%2Farticles%2Fresource-group-move-resources%2F%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23login%20to%20Azure%20RM%20account%20%3CBR%20%2F%3E%20login-azurermaccount%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23get%20Azure%20Subscription%20associated%20with%20this%20account%20%3CBR%20%2F%3E%20Get-AzureRmSubscription%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20To%20select%20a%20default%20subscription%20for%20your%20current%20session%20%3CBR%20%2F%3E%20Get-AzureRmSubscription%20%E2%80%93SubscriptionName%20%E2%80%9C%3CSUBSCRIPTION%20nanme%3D%22%22%3E%E2%80%9D%20%7C%20Select-AzureRmSubscription%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20verify%20your%20default%20subscription%20%3CBR%20%2F%3E%20Get-AzureRmContext%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23get%20azure%20resource%20groups%20%3CBR%20%2F%3E%20get-azurermresourcegroup%20%7C%20sort-object%20-Property%20ResourceGroupName%20%7Cselect%20ResourceGroupName%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23new%20resource%20group%20%3CBR%20%2F%3E%20New-AzureRmResourceGroup%20-Name%20%22DataTier%22%20-Location%20%22South%20Central%20US%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23find%20all%20resources%20associated%20with%20group%20-1%20%3CBR%20%2F%3E%20Find-AzureRmResource%26nbsp%3B%20-ResourceGroupNameContains%20ag2000%20%7Cselect%20ResourceGroupName%2CName%2C%20ResourceType%2C%20Location%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23moving%20multiple%20resource%20together%20if%20there%20are%20dependencies%20(such%20as%20domain%20name%20that%20a%20VM%20depends%20on)%20%3CBR%20%2F%3E%20%24sourcegroup%3D%22ag2000%22%20%3CBR%20%2F%3E%20%24destgroup%3D%22DataTier%22%20%3CBR%20%2F%3E%20%23%24vnet%3DGet-AzureRmResource%20-ResourceName%20ag2000%20-ResourceGroupName%20%24sourcegroup%20-ResourceType%20Microsoft.ClassicNetwork%2FvirtualNetworks%20%3CBR%20%2F%3E%20%24domainname%3DGet-AzureRmResource%20-ResourceName%20agdc%20-ResourceGroupName%20%24sourcegroup%20-ResourceType%20Microsoft.ClassicCompute%2FdomainNames%20%3CBR%20%2F%3E%20%23%24storage%20%3DGet-AzureRmResource%20-ResourceName%20ag2000%20-ResourceGroupName%20%24sourcegroup%20-ResourceType%20Microsoft.ClassicStorage%2FstorageAccounts%20%3CBR%20%2F%3E%20%24dc%3DGet-AzureRmResource%20-ResourceName%20agdc%20-ResourceGroupName%20%24sourcegroup%20-ResourceType%20Microsoft.ClassicCompute%2FvirtualMachines%20%3CBR%20%2F%3E%20%24vm1%20%3D%20Get-AzureRmResource%20-ResourceName%20agsql1%20-ResourceGroupName%20%24sourcegroup%20-ResourceType%20Microsoft.ClassicCompute%2FvirtualMachines%20%3CBR%20%2F%3E%20%24vm2%20%3D%20Get-AzureRmResource%20-ResourceName%20agsql2%20-ResourceGroupName%20%24sourcegroup%20-ResourceType%20Microsoft.ClassicCompute%2FvirtualMachines%20%3CBR%20%2F%3E%20%24vm3%20%3D%20Get-AzureRmResource%20-ResourceName%20%22ag-sql3%22%26nbsp%3B%20-ResourceGroupName%20%24sourcegroup%20-ResourceType%20Microsoft.ClassicCompute%2FvirtualMachines%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Move-AzureRmResource%20-DestinationResourceGroupName%20%24destgroup%20-ResourceId%20%24domainname.ResourceId%2C%24dc.ResourceId%2C%24vm1.ResourceId%2C%24vm2.ResourceId%2C%24vm3.ResourceId%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23verify%20that%20resources%20are%20in%20the%20new%20group%20%3CBR%20%2F%3E%20Find-AzureRmResource%26nbsp%3B%20-ResourceGroupNameContains%20DataTier%20%7Cselect%20ResourceGroupName%2CName%2C%20ResourceType%2C%20Location%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68389iFD02FAC3AC146AA5%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Jack%20Li%20%7CSenior%20Escalation%20Engineer%20%7C%20Microsoft%20SQL%20Server%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fjackli8898%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20twitter%20%3C%2FA%3E%20%7C%20%3CA%20href%3D%22http%3A%2F%2Fdiagmanager.codeplex.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20pssdiag%20%3C%2FA%3E%20%7C%20%3CA%20href%3D%22http%3A%2F%2Fsqlnexus.codeplex.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Sql%20Nexus%3C%2FA%3E%3C%2FSUBSCRIPTION%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-318692%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Feb%2026%2C%202016%20When%20you%20deal%20with%20SQL%20Server%20VMs%20on%20Azure%2C%20there%20are%20many%20operations%20that%20you%20didn%E2%80%99t%20have%20to%20do%20for%20on-premises%20systems.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-318692%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎Jan 15 2019 04:52 PM
Updated by: