Archiving Azure Cosmos Data

Having a play with Azure Cosmos DB over the Easter weekend and played with the Azure SDK. The code is a bit slapdash as I was messing with it in Linqpad – it would need knocking into shape if you were to use this in a Production environment.

Creating Documents

Create a dynamic object


Create a loop to get a few documents in the Collection (I’ve included Thread.Sleep to stop my RUs getting chewed up). I could’ve used the indexer and guids to make the data a bit more random,

Migrating data using the “DocumentDB Migration Tool”

Download the Tool

Setup the source as the Cosmos DB








Set up the Target

Hit the big ole Import button and there you go….

Be mindful here that this will have an impact on your RUs so you might want to scale up accordingly and back down once you’re done.

Removing Exported Data from the Cosmos DB

Initially I was thinking of doing this via the SDK and using the _ts to remove data for a specified date range but then I read about the “Time To Live” feature in the Cosmos DB settings. Simply switch it on and enter an amount of seconds.





To confirm the above I created another 100 records, got the sdk to bring me back the total (204). Then set the TTL above to remove the 104 I’d created earlier.