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
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] []
-
1It 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– Jason Richmeier2018年03月02日 02:12:44 +00:00Commented 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.Alberto Morillo– Alberto Morillo2018年03月02日 03:25:55 +00:00Commented Mar 2, 2018 at 3:25
-
I believe Start-AzureSqlDatabaseCopy has been renamed to New-AzureRmSqlDatabaseCopyIan G– Ian G2020年03月31日 09:15:51 +00:00Commented Mar 31, 2020 at 9:15
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:
- https://learn.microsoft.com/en-us/sql/t-sql/statements/create-database-azure-sql-database?view=azure-sqldw-latest#creating-a-copy-of-a-database-on-another-server
- https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-move-resources
- https://learn.microsoft.com/en-us/azure/sql-database/sql-database-copy
-
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– Jason Richmeier2018年04月16日 13:09:12 +00:00Commented Apr 16, 2018 at 13:09
-
1I like the ARM template approach in the same SO question that you link to stackoverflow.com/a/61648302/73226Martin Smith– Martin Smith2021年09月07日 14:16:43 +00:00Commented Sep 7, 2021 at 14:16
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
-
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 learn.microsoft.com/en-us/azure/azure-sql/database/…Henning Klokkeråsen– Henning Klokkeråsen2021年02月18日 16:59:05 +00:00Commented Feb 18, 2021 at 16:59
Came here via a search engine and notice that the Azure documentation now supports a way to copy databases to different subscriptions