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?

4 Answers 4

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] []

3
  • 1
    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. Commented Mar 2, 2018 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. Commented Mar 2, 2018 at 3:25
  • I believe Start-AzureSqlDatabaseCopy has been renamed to New-AzureRmSqlDatabaseCopy
    – Ian G
    Commented Mar 31, 2020 at 9:15
3

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:

2
  • 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. Commented Apr 16, 2018 at 13:09
  • I like the ARM template approach in the same SO question that you link to stackoverflow.com/a/61648302/73226 Commented Sep 7, 2021 at 14:16
0

Start-AzureSqlDatabaseCopy has been renamed to New-AzureRmSqlDatabaseCopy

New-AzureRmSqlDatabaseCopy
   [-DatabaseName] <String>
   [-Tags <Hashtable>]
   [-CopyResourceGroupName <String>]
   [-CopyServerName <String>]
   -CopyDatabaseName <String>
   [-AsJob]
   -ComputeGeneration <String>
   -VCore <Int32>
   [-LicenseType <String>]
   [-ServerName] <String>
   [-ResourceGroupName] <String>
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Using Azure to create a copy of SQL Database from a snapshot

1
0

Came here via a search engine and notice that the Azure documentation now supports a way to copy databases to different subscriptions

https://learn.microsoft.com/en-us/azure/azure-sql/database/database-copy?tabs=azure-powershell#copy-to-a-different-subscription

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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