This script zips the home assistant configuration (.homeassistant directory, with exclusions defined in exclusions.txt file) and uploads it to dropbox. It even deletes backups older than specified, both from local storage and from dropbox.
This guide is aimed at users running Home Assistant Core in a Python Virtual Environment
I have combined two approaches for backing up configuration of HomeAssistant Core installation, hence most of the credit goes to the original authors.
Become homeassistant user
homeassistant user (or whatever user runs Home Assistant). Change to whatever directory you would like the script to run
sudo -u homeassistant -H -s mkdir -p ~/bin cd ~/bin
apt-get install zip
Dropbox-Uploder (see github project)
curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh chmod +x dropbox_uploader.sh
Run ./dropbox_uploader.sh for the first time to set it up as per instructions on the first run.
Download and Run Script
Download the script and run with the following commands.
wget https://github.com/shajul/ha-scripts/raw/master/backup-homeassistant chmod +x backup-homeassistant
Edit the script file using your preferred text editor (eg nano). Change the paths to reflect your configuration, then simply run
Exclusions text file sample (exclusions.txt) can be found here exclusions.txt
$ ./backup-homeassistant [i] Creating backup [i] Backup complete: /media/hassbackup/hass-config_20220229_112728.zip [i] Deleting backups older then 10 day(s) [i] Uploading hass-config_20220229_112728.zip to dropbox
Set up cron job
and place this on a single line to run cron job at 4 15 am every day. (more options → crontab.guru)
15 4 * * * /home/homeassistant/bin/backup-homeassistant
- You can optionally encrypt the zip files (see
- This usb backup guide - thread id 196964 (sorry, i can post only two links)
- Dropbox-Uploader on github