Cross Subscription Copying of Databases on Windows Azure SQL Database

后端 未结 7 849
北恋
北恋 2020-12-24 13:13

We are about to split our testing and production instances in Windows Azure into two separate subscriptions. Currently we have 3 Windows Azure SQL Database instances that r

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 13:39

    I guess you already have a solution, however for anyone landing here, you can use the Azure PowerShell API's to Create a new server in the source subscription, create a copy and switch over the new server to the destination subscription

    Sample code is available on technet

    The code is self explanatory, however in the interest of SO best practices,

    Key portions of the code are

    Create a new server:

    $newserver = New-AzureSqlDatabaseServer -Location $targetServerLocation -AdministratorLogin $targetServerLoginID -AdministratorLoginPassword $targetServerLoginPassword 
    

    Create a database copy:

    Start-AzureSqlDatabaseCopy -ServerName $sourceServerName -DatabaseName $sourceDatabaseName -PartnerServer $newserver.ServerName  -PartnerDatabase $targetdatabaseName  
    

    Transfer the server

    $uri = "https://management.core.windows.net:8443/" + $sourceSubscriptionID + "/services" + "/sqlservers/servers/" + $newserver.ServerName + "?op=ChangeSubscription" 
    
    Invoke-RestMethod -Uri $uri -CertificateThumbPrint $certThumbprint -ContentType $contenttype -Method $method -Headers $headers -Body $body 
    

提交回复
热议问题