0
votes

We were trying to move a database from one resource group to another resource group. Unfortunately, we got the below error message while tried to move the database :

Move-AzureRmResource : ResourceNotTopLevel : Identifier '' is not a top level resource. At line:1 char:1 + Move-AzureRmResource -DestinationResourceGroupName -ResourceId /subscrip ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Move-AzureRmResource], ErrorResponseMessageException + FullyQualifiedErrorId : ResourceNotTopLevel,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Move AzureResourceCommand

Please see the below command which we used to move the database,

$resource = Get-AzureRmResource -ResourceName Name -ResourceGroupName oldRG

Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId $resource.ResourceId

Could you please tell us how can move the database to another resource group?

3
Do you just need to move one resource, which is the database from one resource group to the other? Do you expect an solution in PowerShell or C#?juvchan
Please go through this link, it will help you out (azure.microsoft.com/en-in/documentation/articles/…)Neeraj Sharma
@juvchan I have to move one database from one resource group to another.itzforu
@NeerajSharma I followed the same doc , and successfully moved other resources like webapp, cloud service, etc. I am facing issue with sql database onlyitzforu

3 Answers

4
votes

You need to move the resource Ids of both the parent database server and the database together to another resource group.

The error: ResourceNotTopLevel : Identifier '' is not a top level resource already clearly stated that the resource Id of your database is not a top level resource. This actually implies that you need to move the top level resource in order to move the child resource.

In this case, your top level resource should be your database server.

The -ResourceId parameter of the Move-AzureRmResource actually takes in string array <String[]>

This link also reports an issue which is similar to yours here.

Hope this helps!

1
votes

According to the command you have given in the question, you didn’t supply values to DestinationResourceGroupName and ResourceId parameters. You should give these parameters respectively the name of the destination Resource Group and the Id of the resource you want to move.

Example:

PS C:\> $resource = Get-AzureRmResource -ResourceName ExampleApp -ResourceGroupName OldRG
PS C:\> Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId $resource.ResourceId

Please see https://azure.microsoft.com/en-in/documentation/articles/resource-group-move-resources/ for more details.

As the Move-AzureRmResource cmdlet is quite new and is updated frequently, please be sure that you are using the last PowerShell version.

1
votes

Thank you all for your reply.

Finally I got reply from Azure support Team. According the support team, It is not possible to move individual databases across resource groups, the entire server needs to be moved

I have sucessfully moved the servers to another resoruce grops.

Below are the commands which I used with powershell to move the SQL servers.

$resource = Get-AzureRmResource -ResourceName {servername} -ResourceGroupName {oldRG}

Move-AzureRmResource -DestinationResourceGroupName {newRG} -ResourceId $resource.ResourceId