Backing Up Home Assistant to Azure Files


This blog post explains how to set up automated Home Assistant backups using Azure Files. This ensures your smart home configuration is always safe and recoverable. If you’ve ever faced the nightmare of a broken setup with no backups, you will understand the importance of this guide. This guide will provide a secure, scalable, and hassle-free solution.

Table of Contents

Why Use Azure Files for Home Assistant Backups?

There are plenty of backup options out there – local drives, NAS devices, cloud storage like Google Drive or OneDrive. Azure Files stands out because:

  • Reliable & Secure: Built-in redundancy and encryption keep your data safe
  • Easy Integration: Works seamlessly with Home Assistant’s Samba share
  • Scalability: Easily scale up without moving files
  • Hassle-free: Set it up once and let backups run on autopilot

Ofcourse, like me – If you’re already using Azure, this is a no-brainer. Let’s set it up!

Setting up Azure Files for Home Assistant

To get started, you’ll need:

Create an Azure File Share

Using the script below, it will create a storage account and an SMB (Server Message Block) share in just a few minutes. This share will act as the destination for your Home Assistant backups.

# Create Azure storage account and SMB share for Home Assistant backups
# Usage: ./create-storage.sh    
# Example: ./create-storage.sh homeassistant uksouth homeassistantbkup backups
# This script creates an Azure storage account and file share for Home Assistant backups.

#!/bin/bash


# Check if the correct number of arguments is provided
if [ "$#" -ne 4 ]; then
    echo "Usage: $0    "
    exit 1
fi

# Assign arguments to variables
RESOURCE_GROUP=$1
LOCATION=$2
STORAGE_ACCOUNT_NAME=$3
FILE_SHARE_NAME=$4
# Check if the storage account name is valid
if ! [[ $STORAGE_ACCOUNT_NAME =~ ^[a-z0-9]{3,24}$ ]]; then
    echo "Error: Storage account name must be between 3 and 24 characters long and can only contain lowercase letters and numbers."
    exit 1
fi
# Check if the resource group already exists
if az group exists --name "$RESOURCE_GROUP"; then
    echo "Resource group $RESOURCE_GROUP already exists."
else
    # Create a resource group
    az group create --name "$RESOURCE_GROUP" --location "$LOCATION"
fi

Create a resource group
az group create --name "$RESOURCE_GROUP" --location "$LOCATION"
# Create a storage account
az storage account create --name "$STORAGE_ACCOUNT_NAME" --resource-group "$RESOURCE_GROUP" --location "$LOCATION" --sku Standard_LRS
# Create azure files
az storage share-rm create --name "$FILE_SHARE_NAME" --resource-group "$RESOURCE_GROUP" --storage-account $STORAGE_ACCOUNT_NAME --quota 1024 --enabled-protocols SMB

Screenshot below shows the storage account and file share has been created successfully in Azure:

Screenshot shows the storage account and file share has been created successfully in Azure

Also, make a note of the:

  • Storage account name & key in access keys, these values will be used in the below to connect to the SMB Share

Connect Home Assistant to Azure Files

Now that Azure file share has been setup, log into Home Assistant and go to:

  • Settings -> System -> Storage and select add new network storage
Screenshot showing Home Assistant network storage connected to Azure File Share

Enter the following details, screenshot above to assist:

  • Name: Enter friendly name of the Azure File Share
  • Usage: Backup
  • Server: .file.core.windows.net
  • Protocol: Samba/Windows (CIFS)
  • Remote share: The name of your Azure file share
  • Username: Storage account name value, which you copied from access keys
  • Password: Storage account name key, which you copied from access keys

Once above has been successful, you will see it appear in Network Storage

Screenshot showing Home Assistant network storage connected to Azure File Share

Configure Home Assistant to backup to Azure Files

Home Assistant’s native backup system makes it easy to schedule regular backups. Lets adjust this to also backup to Azure Files, home assistant go to:

  • Settings -> System -> Backups

You may need to create initial backup config, but I was already doing this, when you are configuring/adjusting your backup policy – set the location to include your newly connected Azure File Share as below:

Screenshot of home assistant, highlighting backup location of Azure Files

Done! Your Home Assistant backups will now be automatically saved to Azure Files, providing peace of mind and disaster recovery readiness.

As you can see below – my backups are also now copied to my Azure Files location:

Screenshot of Azure files, showing sucessful Home Assistant backups

A few tips:

  • Test Your Backups: Don’t wait for a disaster to find out if your backups work. Periodically restore a backup to ensure everything is in order
  • Keep It Simple: Start with a basic setup and tweak it as you go. There’s no need to overcomplicate things

Wrapping up

Backing up your Home Assistant setup might not be the most exciting task, but it’s one of the most important. With Azure Files, I’ve found a solution that’s reliable, scalable, and easy to manage. If you’re still relying on manual backups or local storage, I highly recommend giving Azure Files a try.

Setting up Azure Files for Home Assistant backups is a simple yet powerful way to protect your smart home from unexpected failures.

GitHub repository containing code above


Share this content:

I am a passionate blogger with extensive experience in web design. As a seasoned YouTube SEO expert, I have helped numerous creators optimize their content for maximum visibility.

Leave a Comment