Backup Docker-based Home Assistant to S3

For context I run Home Assistant via Docker (really via docker-compose) on a Raspberry Pi 4. Previously I ran it on HASSIO but ran into some outage issues with HASSIO and I desired more control.

I maintain the configuration files at /opt/homeassistant thus I use the following script to backup the configuration to AWS S3:


# Script provides an AWS S3-backed backup for Docker-installed Home Assistant
# ---------------------------------------------------------------------------
# + configured via bash variables below
# + requires use of AWS credential profiles

date=$(date '+%Y-%m-%d') # want hour, minute - update to '%Y-%m-%d-%H-%M'


# ---------------------------------------------------------------------------
tar czvf ${basepath}/${date}-${filename} ${basepath}/homeassistant
aws s3 cp --profile=${profile} --storage-class ${storage} --acl ${acl} /opt/${date}-${filename} s3://${bucket}/
find ${basepath} -name "*-${filename}" -type f -mtime +30 -exec rm -f {} \;

You need to do a few things:

Note: this script will hold the files for 30 days on the local device before destroying them via the find and exec command.

# CRON things
0 2 */15 * * /bin/bash /opt/
[ home-automation linux pi ]