Migrating Microsoft Azure Cosmos DB collections between different Azure subscriptions

This article will help migrating the azure cosmos db data between different accounts and subscription.

3 Simple steps:

  1. Download dt.exe https://cosmosdbportalstorage.blob.core.windows.net/datamigrationtool/2018.02.28-1.8.1/dt-1.8.1.zip
  2. Replace appropriate values in the below script
  3. Run the script and check the results

The dt.exe can handle different types of sources

JSON files
MongoDB
SQL Server
CSV files
Azure Table storage
Amazon DynamoDB
HBase


$sourceaccountname="https://name.documents.azure.com:443/"
$sourceaccountkey="<source account key>"
$sourcedatabase="<source database name>"
$targetaccountname="https://name.documents.azure.com:443/"
$targetaccountkey="<target account name>"
$targetdatabase="<target database name>"
$collectionstomigrate = @("collection1","collection2","collection3")
foreach ($collectionname in $collectionstomigrate)
{
Write-Host "Porcessing the collection $($collectionname)"
& c:\tools\dt1.7\dt.exe /s:DocumentDB /s.ConnectionString:"AccountEndpoint=$sourceaccountname;AccountKey=$sourceaccountkey;Database=$sourcedatabase;" /s.Collection:$collectionname /t:DocumentDBBulk /t.ConnectionString:" AccountEndpoint=$targetaccountname;AccountKey=$targetaccountkey;Database=$targetdatabase;" /t.Collection:$collectionname /t.CollectionThroughput:1000 /t.UpdateExisting:true
}

view raw

cosmosdb.ps1

hosted with ❤ by GitHub

Note: Please make sure you carry over the indexing policy from the source database to the target database.

 

Happy Migration.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.