5

Getting straight to the point, is this even possible?

I have successfully copied an Azure SQL database within the same subscription. In doing so, I kept it simple by copying the database to the same server (within the subscription). I used the Powershell commands Add-AzureRmAccount and New-AzureRmSqlDatabaseCopy.

I have tried executing the Add-AzureRmAccount twice (once for each subscription) but this seems to replace the first subscription with the second in the context as the New-AzureRmSqlDatabaseCopy command reports that it cannot find the specified resource group (which exists in the source subscription).

All that said, if this is something that is possible, what are the steps / commands that I need to execute?

2

Create a new Azure SQL Server on a different resource group.

New-AzureSqlDatabaseServer -Location "East US" -AdministratorLogin "AdminLogin" -AdministratorLoginPassword "AdminPassword"

Copy the source database to the newly created Azure SQL Server.

Start-AzureSqlDatabaseCopy -ServerName "SourceServer" -DatabaseName "Orders" -PartnerServer "NewlyCreatedServer" -PartnerDatabase "OrdersCopy"

Move the resource group of the Newly created Azure SQL Server to another subscription.

Move-AzureRmResource -DestinationResourceGroupName [-DestinationSubscriptionId ] -ResourceId [-Force] [-ApiVersion ] [-Pre] [-DefaultProfile ] [-InformationAction ] [-InformationVariable ] [-WhatIf] [-Confirm] []

  • It appears that the last command will not work in my case as the subscriptions I am copying between are not under the same tenant ID. At any rate, I marked your solution as the accepted answer as I think it would have worked otherwise. – Jason Richmeier Mar 2 '18 at 2:12
  • Thanks! Just to let you know you can use SQL Data Sync between subscriptions. On the destination recreate the same schema and start SQL Data Sync. – Alberto Morillo Mar 2 '18 at 3:25
2

Another option is to use CREATE DATABASE, as per Richard Hauer's answer on Stackoverflow (which I executed from SQL Server Management Studio v17.5):

CREATE DATABASE db_copy AS COPY OF ozabzw7545.db_original;

Some important notes:

  • SQL admin account and password were the same on both servers.
  • Servers were in different subscriptions.
  • Servers were on the same Tenant, checked via Azure PowerShell console with:

    (Get-AzureRmSubscription -SubscriptionName <your-source-subscription>).TenantId 
    (Get-AzureRmSubscription -SubscriptionName <your-destination-subscription>).TenantId
    

You can monitor the progress with:

SELECT state_desc, name 
FROM sys.databases 

Reference Links:

  • Similar to the previous answer, this might have worked for me had the two subscriptions been created under the same tenant ID. Since they are not, I doubt that it will work as you listed this as one of the requirements. – Jason Richmeier Apr 16 '18 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.