I’m surprised to how difficult it is to find a best-practice for this.
Here’s what I’ve done:
- Create an automation in HA to make a backup:
alias: "Backup: Create backup"
description: ""
trigger:
- platform: time
at: "03:00:00"
condition:
- condition: time
weekday:
- mon
- wed
- sat
action:
- service: backup.create
data: {}
mode: single
-
Install Rclone on the host machine: https://rclone.org/
-
Create a script on the host machine
#!/bin/bash
# Backup HA
echo "Backing up Home Assistant to pCloud..."
rclone sync /opt/appdata/homeassistant/backups pCloud:/homeassistant_backup/ -P
echo "Backup of Home Assistant database to pCloud completed."
# Remove oldest HA backups
echo "Removing oldest Home Assistant backups..."
ls -t /opt/appdata/homeassistant/backups | tail -n +4 | xargs -I {} rm -f "/opt/appdata/homeassistant/backups/{}"
echo "Finnished removing old Home Assistant backups."
- Setup a cron job on the host to run the script each night.
Pro: It works, and by using HA’s own backup functionality, removes the risk of database issues. Also, no need to stop and start Home Assistant.
Con: Ideally, I would have liked to do also the HA backup from the script, but I haven’t managed to figure out how to do that.
Hope this helps someone.