diff --git a/V2/home_assistant_backup.conf b/V2/home_assistant_backup.conf new file mode 100644 index 0000000..3cf8050 --- /dev/null +++ b/V2/home_assistant_backup.conf @@ -0,0 +1,32 @@ +### Global Settings ### +# Set your Home Assistant SSH credentials +HA_SSH_KEY="SSH_PRIVATE_KEY" # Replace with your SSH Private key for HomeAssistant +HA_SSH_USER="SSH_USER" # Replace with your HomeAssistant server username (Default is root) +HA_SSH_HOST="SSH_HOST_IP_OR_HOSTNAME" # Replace with your HomeAssistant server IP address +HA_SSH_PORT="SSH_PORT" # Replace with your HomeAssistant server port + +## Storage +# Set the backup destination path +BACKUP_DEST="BACKUP_FILE_DESTINATION" # Replace with the location for the backup files + +# Set the location of the Home Assistant backups (Set to default location /backup) +# If you have a custom install, using the likes of Supervised +# this location should normally be /usr/share/hassio/backup +BACKUP_FILE_LOCATION="/backup" + +# Storage threshold (in KB) for triggering cleanup +STORAGE_THRESHOLD_KB=2097152 # 2GB = 2 * 1024 * 1024 KB +# Set clean up old backups (adjust the number of days to keep) +LOCAL_BACKUP_CLEANUP="90" # Set the number of days that local backup files will be kept for (Default 90 days) +REMOTE_BACKUP_CLEANUP="30" # Set the number of days that backups on the Home Assistant server will be kept for (Default 30 days) + +## Notification Settings +# ntfy settings +NTFY_ENABLED=false # Set to 'true' to enable ntfy notifications +NTFY_SERVER="NTFY_SERVER_FQDN_ADDRESS" # Replace with your ntfy server address +NTFY_TOPIC="NTFY_TOPIC" # Replace with your ntfy topic + +# Discord webhook settings +DISCORD_ENABLED=false # Set to 'true' to enable Discord notifications +DISCORD_WEBHOOK_URL="DISCORD_WEBHOOK_URL" # Replace with your Discord webhook URL + diff --git a/V2/home_assistant_backup.sh b/V2/home_assistant_backup.sh index 645aed6..be1c18f 100644 --- a/V2/home_assistant_backup.sh +++ b/V2/home_assistant_backup.sh @@ -1,37 +1,17 @@ #!/bin/bash #set -x -### Global Settings ### -# Set your Home Assistant SSH credentials -HA_SSH_KEY="SSH_PRIVATE_KEY" # Replace with your SSH Private key for HomeAssistant -HA_SSH_USER="SSH_USER" # Replace with your HomeAssistant server username (Default is root) -HA_SSH_HOST="SSH_HOST_IP_OR_HOSTNAME" # Replace with your HomeAssistant server IP address -HA_SSH_PORT="SSH_PORT" # Replace with your HomeAssistant server port +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CONFIG_FILE="$SCRIPT_DIR/home_assistant_backup.conf" -## Storage -# Set the backup destination path -BACKUP_DEST="BACKUP_FILE_DESTINATION" # Replace with the location for the backup files +if [ ! -f "$CONFIG_FILE" ]; then + echo "Error: Config file not found: $CONFIG_FILE" + exit 1 +fi -# Set the location of the Home Assistant backups (Set to default location /backup) -# If you have a custom install, using the likes of Supervised -# this location should normally be /usr/share/hassio/backup -BACKUP_FILE_LOCATION="/backup" - -# Storage threshold (in KB) for triggering cleanup -STORAGE_THRESHOLD_KB=2097152 # 2GB = 2 * 1024 * 1024 KB -# Set clean up old backups (adjust the number of days to keep) -LOCAL_BACKUP_CLEANUP="90" # Set the number of days that local backup files will be kept for (Default 90 days) -REMOTE_BACKUP_CLEANUP="30" # Set the number of days that backups on the Home Assistant server will be kept for (Default 30 days) - -## Notification Settings -# ntfy settings -NTFY_ENABLED=false # Set to 'true' to enable ntfy notifications -NTFY_SERVER="NTFY_SERVER_FQDN_ADDRESS" # Replace with your ntfy server address -NTFY_TOPIC="NTFY_TOPIC" # Replace with your ntfy topic - -# Discord webhook settings -DISCORD_ENABLED=false # Set to 'true' to enable Discord notifications -DISCORD_WEBHOOK_URL="DISCORD_WEBHOOK_URL" # Replace with your Discord webhook URL +# Load variables +# shellcheck disable=SC1090 +source "$CONFIG_FILE" ### Script ### ## Sanity Check## @@ -158,7 +138,7 @@ send_ntfy_notification "Backup process started at $TIMESTAMP" send_discord_notification "Backup process started at $TIMESTAMP" # Check available disk space on Home Assistant server -AVAILABLE_SPACE=$(ssh -i "$HA_SSH_KEY" -p "$HA_SSH_PORT" "$HA_SSH_USER@$HA_SSH_HOST" "df --output=avail / | tail -n 1") +AVAILABLE_SPACE=$(ssh -i "$HA_SSH_KEY" -p "$HA_SSH_PORT" "$HA_SSH_USER@$HA_SSH_HOST" "df -k / | tail -n 1 | tr -s ' ' | cut -d ' ' -f 4") if [ "$AVAILABLE_SPACE" -lt "$STORAGE_THRESHOLD_KB" ]; then echo "Disk space is less than 2GB on Home Assistant server. Proceeding with remote backup cleanup..." # Remove old backups on Home Assistant server if less than 2GB available