Backup Azure Storage using Azure Functions in 3 easy steps


At Luminis, we develop many Cloud Native Solutions in Azure, but there is no easy way to make backups for our Azure Storage Accounts. So we’ve developed a NuGet package that does exactly that, and you can use it too! Here are 3 easy steps how to implement this using an Azure Function.

1. Create timer trigger

Add a new timer trigger to your existing project. If you are using Visual Studio, you can right click on your existing Function App project to add a new Azure Function.

public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
     log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

If you don’t have a Function app, yet this blog should get you started.

2. Install the NuGet package

Install the NuGet package in your project, through the NuGet window or the Visual Studio package manager:

Install-Package Luminis.AzureStorageBackup -Version 1.6.0

3. Configure the backup

Now the only thing left to do, is providing the correct configuration, so the library knows what to backup, and where to.

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");

For more information checkout the GitHub page. Interested, and you want want to learn more about Azure Functions checkout our traning about Microservice using Azure Functions from the Luminis Academy