Upgrades and Backups
Below are a couple scripts that can be used to upgrade your Home Assistant Core install (if you followed my install write up previously), and to create backups of the installation on a schedule.
I have taken the backup script from another site, as he did a pretty darn good job and there is no need to re-invent that wheel. I recommend checking out his site. He's got some really good information and goes into a lot more detail then what I am providing.
NUXREF.COM: THE PERFECT HOME ASSISTANT CENTOS 8 INSTALLATION
Here is a quick upgrade script. Be sure to switch to the HA user before running it.
cat << EOF > /opt/ha/upgrade_ha.sh
## actiave environment
. ./bin/activate
## upgrade ha
echo
echo "----- CHECKING FOR HA UPGRADE -----"
echo
pip3 install --upgrade homeassistant
## upgrade components - you can comment these out
## I added them because I installed them.
echo
echo "----- CHECKING FOR HA FRONTEND UPGRADE -----"
echo
pip3 install --upgrade home-assistant-frontend
echo
echo "----- CHECKING FOR HA ZIGBEE UPGRADE -----"
echo
pip3 install --upgrade homeassistant-pyozw
echo
echo "----- CHECKING FOR COLORLOG UPGRADE -----"
echo
pip3 install --upgrade colorlog
echo
echo "----- CHECKING FOR FLASK SQLALCHEMY UPGRADE -----"
echo
pip3 install --upgrade flask-sqlalchemy
echo
echo "----- CHECKING FOR FLASK PYTURBOJPEG UPGRADE -----"
echo
pip3 install --upgrade PyTurboJPEG
echo
echo "----- CHECKING FOR FLASK WHEEL UPGRADE -----"
echo
pip3 install --upgrade wheel
## exit activation ha sudo
exit
EOF
# change permissions on the script
chown ha.ha /opt/ha/upgrade_ha.sh
# run it
su - ha
./upgrade_ha.sh
Here is the backup script and a cron to run it.
<< cat > /opt/ha/bin/backup_ha.sh
#!/bin/sh
# Create a backup of Home Assistant
TARGET=/opt/ha/backups
SOURCE=/etc/ha
[ ! -d "$TARGET" ] && /usr/bin/mkdir -p "$TARGET"
[ ! -d "$TARGET" ] && exit 1
tar cfz "$TARGET/$(date +'%Y.%m.%d')-config.tgz" -C $SOURCE .
RET=$?
# Tidy; Keep X days worth
find -L $TARGET/ -mindepth 1 -maxdepth 1 -name "*.config.tgz" -mtime +30 -delete
exit $RET
EOF
cat << EOF > /etc/cron.d/backup_ha
# backup home assistant
0 0 * * 0 ha /opt/ha/bin/backup_ha.sh &>/dev/null
EOF
Hope it helps. Take care!