Skip to main content

Azure Storage Synchronization between Azure Regions from China and the rest of them

Working with Azure Regions from China is sometimes a little bit more complicated. One of the issues that I encountered is the ability to sync content between different Azure Regions. Inside Azure regions that are in China, things go very smooth.
The challenge appears in the moment when you need to handle data synchronisation between a region from China and a one from Europe, for example. I had this case between China East 2 and North Europe. There is no out of the box, the mechanism to do something like that and you need to handle this synchronisation by yourself.
We will take a look at two different scenarios. A simple one, where is less automation, but the investment is lower, and in 10 minutes you have the sync mechanism in place. The second one is a little more complex, but can be used with success for recurrent activities.

Simple Use Case
For simple scenarios, you should not start to write code by yourself. Take a look at AzCopy that is a command-line tool that enables us to copy content from local machines to Azure Storage or from one Azure Storage to another.
Using Azure Copy, we can run a command line that copy content from one container to another. You can specify what policy you want to use at the moment when content blobs with the same name already exist.
.\azcopy copy 
    ' /demo/copy' 
    --overwrite false
In the above example, we just copied content from one location from North Europe to a storage account from China. Don’t forget that the blobs that it is used as a source should be public or you should also include de SAS key (as I have done in the example). By default the overwrite is set to true, meaning that if you already the same content in the destination location, the content is overwritten.
I’ve also done some performance test to see how long it takes to copy content from one location to another. You can see below the output of it.

North Europe     10GB     send to East China           1h52m                  100% success rate             
Japan West         10GB     send to East China           1h01m                  100% success rate
East China           1GB        send to North Europe     0h21m                  100& success rate
East China           1GB        send to Japan West         0h16m                  100& success rate

For scenarios where you need to be able to repeat the process over and over again, and you want to have better control, I would use Azure Data Factory. It is allowing us to define a pipeline where we would have a copy activity from one Azure Blob to another one. The tricky part here is how to specify the storage from another subscription. Because in Azure Regions location in China you will use a different account and a separate subscription, you are not able to use the Copy Data Tool available inside the Azure Data Factory.
The good part is that we have a connector inside Data Factory that can use a SAS for Azure Blob Storage. The approach would be to run in North Europe the Data Factory Pipeline that would pus the content to the East China location by using the SAS key for access and authorisation.

    "name": "AzureBlobStorageLinkedService",
    "properties": {
        "type": "AzureBlobStorage",
        "typeProperties": {
            "sasUri": {
                "type": "SecureString",
                "value": "*?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-11-09T21:22:50Z&st=2019-10-30T13:22:50Z&spr=https&sig=9IxJn%2BRYgaBu5R%dsds2BG%2Frf4spjNBxYXagNu7BVx1PT1eTk%1D'"
        "connectVia": {
            "referenceName": "Linked.....",
            "type": "IntegrationRuntimeReference"

To sum up
We can imagine different solutions, using Azure Functions, Azure VMs or Azure Batch, but these two solutions are the one that I used. The first one, based on AzCopy, is simple and can be used with success for a PoC or for cases you you need to move binary content. The one based on Azure Data Factory works with success when you need to do heavy data sync between the two locations.


Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.