Noticed that my backup-pull script (which Im sure I found in these archives) was not working. I think it was because of a change to the LOGIN
flow as well as lisitng backups.
This scripts requests a new backup from Hubitat, such that it doesnt pull the most recent, but generates a new one.
If someone could reference an update to pull the most recent, would appreciate it, but this works
#!/bin/bash
set -e
he_login="LOGIN"
he_passwd="PASSWORD"
he_ipaddr="IP.ADDRESS"
cookiefile="/tmp/hubitat.cookie"
sessionfile="/tmp/hubitat.cookie.session"
archive_dir="/PATH/TO/BACKUPS"
# Remove old cookies if they exist
rm -f $cookiefile $sessionfile
# cleanup backups (10 days)
touch $archive_dir/temp.lzf
find $archive_dir/*.lzf -mtime +10 -exec rm {} \;
# Step 1: Fetch login page to get CSRF token
curl -k -c $cookiefile -s https://$he_ipaddr/login | grep -o 'name="_csrf" value="[^"]*' | cut -d '"' -f3
# Step 2: Log in using CSRF token and store session cookies separately
curl -k -c $sessionfile -b $cookiefile -d "username=$he_login" -d "password=$he_passwd" -d "_csrf=$csrf_token" https://$he_ipaddr/login
# Debug: Verify successful authentication by checking session cookies
if ! grep -q "HUBSESSION" $sessionfile; then
echo "Error: Login failed, session cookie not found."
exit 1
fi
# Step 3: Generate a backup file
curl -k -sb $sessionfile "https://$he_ipaddr/hub/backupDB?fileName=latest" -o "$archive_dir/Hubitat_$(date +%Y-%m-%d-%H%M).lzf"
# Clean up cookie files
rm -f $cookiefile $sessionfile
echo "Backup completed."