#!/usr/bin/env bash set -euo pipefail if [[ $# -ne 1 || ! -f "$1" ]]; then echo "Usage: $0 path/to/home-assistant-backup.tar.gz" >&2 exit 2 fi script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" archive="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" cd "$script_dir" if [[ -f "$script_dir/.env" ]]; then set -a # shellcheck disable=SC1091 . "$script_dir/.env" set +a fi volume="${HOMEASSISTANT_CONFIG_VOLUME:-home-assistant-config}" # A safety copy of the current state before the data is replaced. bash "$script_dir/backup.sh" docker compose stop home-assistant restart_container() { docker compose start home-assistant >/dev/null } trap restart_container EXIT docker run --rm \ -v "${volume}:/target" \ -v "${archive}:/backup.tar.gz:ro" \ alpine:3.22 \ sh -c 'find /target -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + && tar -C /target -xzf /backup.tar.gz' echo "Backup restored from: $archive" echo "If you are rolling back, set the image version to the one the archive was made with."