1

I have One blob which contains my users' CVs.

My site is live. Now I want to copy From one blob to another blob with different storage account.

Here is my code to copy blob

        CloudStorageAccount sourceStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("sourceStorageConnectionString"));
        CloudStorageAccount targetStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("targetStorageConnectionString"));

        CloudBlobClient sourceCloudBlobClient = sourceStorageAccount.CreateCloudBlobClient();
        CloudBlobClient targetCloudBlobClient = targetStorageAccount.CreateCloudBlobClient();

        CloudBlobContainer sourceContainer = sourceCloudBlobClient.GetContainerReference(CloudConfigurationManager.GetSetting("sourceContainer"));
        CloudBlobContainer targetContainer = targetCloudBlobClient.GetContainerReference(CloudConfigurationManager.GetSetting("targetContainer"));
        targetContainer.CreateIfNotExists();

        // Copy each blob
        foreach (IListBlobItem blob in sourceContainer.ListBlobs(useFlatBlobListing: true))
        {

            Uri thisBlobUri = blob.Uri;

            var blobName = Path.GetFileName(thisBlobUri.ToString());
            Console.WriteLine("Copying blob: " + blobName);

            CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(blobName);
            CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(blobName);

            Task task = TransferManager.CopyAsync(sourceBlob, targetBlob, true /* isServiceCopy */);

        }

but my concern is: If this copy operation is running and one of the Cv is updated by any user then will it be effect on live site or in copy operation?

1
  • the version of the blob when the copy operation started will be copied.
    – Aravind
    Commented Feb 6, 2017 at 10:13

1 Answer 1

3

You're making an async service-side copy (isServiceCopy = true). If the source changes during the copy, its ETag changes, which invalidates the copy. You'd then need to re-start the failed copy.

Note: If you take a snapshot prior to the copy, then you can safely copy the snapshot, knowing that its contents cannot change (even if the base blob changes). You'd need to then deal with cleaning up snapshots, but it's a way to get around concurrent-write issues on the source blob (or you can simply retry the copy, as I mentioned).

I posted an answer to a similar question, here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.