How Do I Backup Azure Tables and Blobs

Viewed 16955

I store data in Azure Storage tables and blob storage. I would like to automatically backup my data to protect against accidental data corruption by users or by a software issue. There isn't a good solution for this from Microsoft and, while there are paid solutions for automatic backups, it seems like there should be a straight-forward way to backup and restore this data.

6 Answers

We wrote a .NET library that backups tables and blobs. You can easily implement this in an azure function timer trigger.

In this blog I explain how to implement it using an Azure function.

[FunctionName("Function1")]
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log, ExecutionContext context)
{
  var sourceAccountName = Environment.GetEnvironmentVariable("BackupSourceAccountName");
  var sourceKey = Environment.GetEnvironmentVariable("BackupSourceAccountKey");

  var backupAzureStorage = new Luminis.AzureStorageBackup.BackupAzureStorage(sourceAccountName, sourceKey, log, context.FunctionAppDirectory);

  var destinationAccountName = Environment.GetEnvironmentVariable("BackupDestinationAccountName");
  var destinationKey = Environment.GetEnvironmentVariable("BackupDestinationAccountKey");
  var destinationContainerName = Environment.GetEnvironmentVariable("BackupDestinationContainer");

  // Backup Tables
  await backupAzureStorage.BackupAzureTablesToBlobStorage("table1,table2", destinationAccountName, destinationKey, destinationContainerName, "tables");

  // Backup Blobs
  await backupAzureStorage.BackupBlobStorage("container1,container2", destinationAccountName, destinationKey, destinationContainerName, "blobs");
}

Have a look at the Microsoft Azure Storage Data Movement Library

This seems to offer most of the functionality of AzCopy, but in a nuget package, so you can use it pretty much anywhere you like.

We are running this in a triggered webjob and it seems to be performing really well for both table and blob storage backup.

If you are still looking for a solution for this problem, please look at a package I released on NuGet AzureTableUtilities

You can copy a table to a file or blob file, restore a table from a file or blob file as well as copy to another table on the same account or a different account. Filtering on PartitionKey and Timestamp is also available.

I also created a reference command line code base and put it on GitHub which allows this to be executed from a command line or Docker container.

Let me know if this doesn't quite match what you want, and I'll see if I can enhance the functionality. I realize the tool itself does not "automatically" back Azure Tables data up; however, using the command line example either under windows directly or in a Docker container, I think you'd be able to set up whatever process(es) you wanted to back things up.

Related