A method to compare blobs in different Azure blob storage accounts

I was recently asked to run a comparison of the blobs in two Azure Storage Accounts, where they should contain the same blob entries. However, some of the entries had been deleted from one account. Since it requires scanning the whole account it is expensive in cost and time. The fastest mechanism I found (and I’m sure there are better ways, please comment) was;

var blobsInBackupContainer = backupContainer.ListBlobs(useFlatBlobListing: true).OfType<CloudBlockBlob>().Select(b => b.Name);
var blobsInPrimaryContainer = primaryContainer.ListBlobs(useFlatBlobListing: true).OfType<CloudBlockBlob>().Select(b => b.Name);                

var missing = blobsInBackupContainer.Except(blobsInPrimaryContainer);
Console.WriteLine($"Missing count {missing.Count()}");
foreach (var item in missing)
    Console.WriteLine($"Missing item = {item}");

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s