Files
Home-Assistant-Backup-Script/README.md
T

110 lines
5.2 KiB
Markdown
Raw Permalink Normal View History

# Home Assistant Backup Automation Scripts
These scripts automate the backup process for **Home Assistant** servers, enabling you to create, transfer, and manage backups. The backups are securely transferred from the Home Assistant server to your local machine, with options for cleaning up old backups based on configurable retention periods.
## Overview
### Features:
- **Backup Creation**: Automates the process of creating backups on your Home Assistant server.
- **Backup Transfer**: Transfers the generated backups to a local machine for safekeeping.
- **Old Backup Cleanup**: Automatically cleans up old backups on both the Home Assistant server and local machine after a specified retention period.
- **Notification Support** (Optional): Configure **ntfy** or **Discord** notifications to alert you about the backup status (available in the first script version).
## Requirements
Both scripts require the following to function correctly:
- **Bash shell** (on your local machine and Home Assistant server)
- **SSH** access to the Home Assistant server
- **`scp`** and **`ssh`** tools
- **Home Assistant** installed on the server with the `ha` CLI tool
2026-11-06 22:59:58 +00:00
- **Optional**: Access to a notification service (for Version 2&3)
## Configuration
Go port of `home_assistant_backup.sh`. Uses the same `home_assistant_backup.conf`.
## Build
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o ha-backup .
Override the version at build time if needed:
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.version=3.1.2" -o ha-backup .
Check the version:
./ha-backup -version
Cross-compile examples:
GOOS=linux GOARCH=amd64 go build -o ha-backup-linux-amd64 .
GOOS=linux GOARCH=arm64 go build -o ha-backup-linux-arm64 . # Raspberry Pi / ARM NAS
## Logging
ha-backup writes a log to `/var/log/ha-backup.log` by default. Each line is timestamped, and the file is appended to on every run. The same output is still printed to the console.
### Create the log file
Writing to `/var/log` requires elevated permissions, so create the file once and give ownership to the user that runs the backup. Replace `backupuser` with that user (use `root` if you run it as root):
If you'd rather do it in steps:
```
sudo touch /var/log/ha-backup.log
sudo chown backupuser:backupuser /var/log/ha-backup.log
sudo chmod 640 /var/log/ha-backup.log
```
If the log file can't be opened, ha-backup prints a warning and continues the backup without file logging.
### Change or disable the log location
Set `LOG_FILE` in `home_assistant_backup.conf`:
```bash
LOG_FILE="/var/log/ha-backup.log" # default
LOG_FILE="/home/backupuser/ha-backup.log" # custom path
LOG_FILE="none" # disable file logging
```
## Run
./ha-backup # looks for home_assistant_backup.conf next to the binary, then in cwd
./ha-backup -config /path/to.conf
Requires `ssh` and `scp` on the machine running it. `jq` and `yq` are no longer needed.
## Three Versions of the Script:
This project used to contain three versions of this project. V1 and V2 have both been moved to their own repositorys and archived as they will no longer be developed and previous releases will be kept but marked as "Pre-Release"
1. **Version 1: See [https://git.ncltech.co.uk/phil/Home-Assistant-Backup-Script-V1](https://git.ncltech.co.uk/phil/Home-Assistant-Backup-Script-V1)**
2. **Version 2: See [https://git.ncltech.co.uk/phil/Home-Assistant-Backup-Script-V2](https://git.ncltech.co.uk/phil/Home-Assistant-Backup-Script-V2)**
## Disclaimer
**The software is provided "as-is" without any warranties or guarantees of any kind.**
By using this script, you acknowledge and agree that:
- **No Warranty**: The script is provided without any warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. The entire risk arising out of the use or performance of the script remains with you.
- **Data Loss**: The author cannot be held responsible for any data loss, damage to your system, or any other kind of loss resulting from the use of this script. You are solely responsible for backing up your data and ensuring the integrity of your systems before using the script.
- **Use at Your Own Risk**: You are using this script at your own risk. The author shall not be liable for any damages, including but not limited to direct, indirect, incidental, special, consequential, or punitive damages, arising out of the use of or inability to use the script.
- **No Support**: The script is provided "as-is" with no formal support or maintenance. The author does not provide any guarantees of continued functionality, updates, or support.
- **Modifications and Redistribution**: If you modify or redistribute the script, you do so at your own risk. You are solely responsible for ensuring that any modifications or redistributed versions do not cause harm or violate any laws.
By using or modifying this script, you agree to indemnify and hold harmless the author from any and all claims, damages, liabilities, and expenses arising from your use or modification of the script.
---
2026-11-06 22:59:58 +00:00
Use of this project is subject to the terms above. If you do not agree with this disclaimer, you should not use it.
2024-02-01 23:13:23 +00:00