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?

Jason Richmeier
  • 201
  • 1
  • 3
  • 5

4 Answers4

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:

Colin K
  • 131
  • 3
  • 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
  • I like the ARM template approach in the same SO question that you link to https://stackoverflow.com/a/61648302/73226 – Martin Smith Sep 07 '21 at 14:16
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] []

Alberto Morillo
  • 1,600
  • 7
  • 8
  • 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. – Jason Richmeier Mar 02 '18 at 02: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 02 '18 at 03:25
  • I believe Start-AzureSqlDatabaseCopy has been renamed to New-AzureRmSqlDatabaseCopy – Ian G Mar 31 '20 at 09:15
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

armitage
  • 1,402
  • 2
  • 14
  • 20
Ian G
  • 101
  • This won't solve the problem of moving between subscriptions, which was the question. "The Azure portal, PowerShell, and the Azure CLI do not support database copy to a different subscription." - from https://learn.microsoft.com/en-us/azure/azure-sql/database/database-copy?tabs=azure-powershell – Henning Klokkeråsen Feb 18 '21 at 16:59
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

Stephen Morris - Mo64
  • 4,056
  • 1
  • 9
  • 17