3.7 KiB
Home Assistant Backup Script
This script automates the process of creating and copying backups from a Home Assistant server to a local machine. It includes functionality for:
- Creating a new backup on the Home Assistant server.
- Copying the backup file to a specified local destination.
- Cleaning up old backups based on a specified retention period.
Requirements
- Bash shell
- SSH access to your Home Assistant server
scpandsshtools- Access to a Home Assistant server with the
hacommand line tool installed
Configuration
Before using the script, you need to configure the following variables:
Global Settings
- HA_SSH_KEY: Path to your SSH private key for accessing the Home Assistant server.
- HA_SSH_USER: The SSH username to use for connecting to the Home Assistant server (usually
root). - HA_SSH_HOST: The IP address or hostname of your Home Assistant server.
- BACKUP_DEST: The destination directory on your local machine where the backup file will be stored.
Backup Retention
- The script will automatically clean up backup files on the local machine that are older than 30 days. You can adjust this retention period by modifying the
-mtime +30argument in thefindcommand to a different number of days.
Script Flow
- Backup Creation: The script connects to the Home Assistant server via SSH and creates a new backup using the
ha backup newcommand. It generates a timestamped name for the backup. - Backup Transfer: The backup file is copied from the Home Assistant server to your local machine using
scp. - Local Backup Cleanup: The script will automatically remove local backups that are older than the configured retention period (default is 30 days).
- Completion Message: A success message is displayed after the backup process is complete.
Usage
-
Clone or Download the Script:
- Clone the repository or download the script file.
-
Make the Script Executable:
chmod +x home_assistant_backup.sh
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.
Use of this script is subject to the terms above. If you do not agree with this disclaimer, you should not use the script.