This article will help migrating the azure cosmos db data between different accounts and subscription.
3 Simple steps:
- Download dt.exe https://cosmosdbportalstorage.blob.core.windows.net/datamigrationtool/2018.02.28-1.8.1/dt-1.8.1.zip
- Replace appropriate values in the below script
- 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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\dt–1.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 | |
} |
Note: Please make sure you carry over the indexing policy from the source database to the target database.
Happy Migration.