Added backup script
This commit is contained in:
parent
43a33bc1c6
commit
3813976422
22
ha-backup.sh
Normal file
22
ha-backup.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
# Set your Home Assistant SSH credentials
|
||||
HA_SSH_KEY="/home/user/.ssh/HomeAssistant-key"
|
||||
HA_SSH_USER="root"
|
||||
HA_SSH_HOST="HOME.ASSISTANT.IP.ADDRESS"
|
||||
|
||||
# Set the backup destination path
|
||||
BACKUP_DEST="/BACKUP/DESTINATION"
|
||||
|
||||
# Create a backup on the Home Assistant server and extract the slug
|
||||
BACKUP_OUTPUT=$(ssh -i "$HA_SSH_KEY" "$HA_SSH_USER@$HA_SSH_HOST" "ha backup new --name=auto_backup_$(date '+%Y-%m-%d_%H-%M-%S')")
|
||||
BACKUP_SLUG=$(echo "$BACKUP_OUTPUT" | awk '/slug:/ {print $2}')
|
||||
|
||||
# Copy the backup file from Home Assistant to your local machine
|
||||
scp -i "$HA_SSH_KEY" "$HA_SSH_USER@$HA_SSH_HOST:/backup/${BACKUP_SLUG}.tar" "$BACKUP_DEST/${BACKUP_SLUG}_$(date '+%Y-%m-%d_%H-%M-%S').tar"
|
||||
|
||||
# Clean up old backups if needed (adjust the number of days to keep)
|
||||
find "$BACKUP_DEST" -name '*.tar' -mtime +303030303030303030303030303030303030303030303030303030303030 -exec rm {} \;
|
||||
|
||||
echo "Backup completed successfully: $BACKUP_DEST/${BACKUP_SLUG}_$(date '+%Y-%m-%d_%H-%M-%S').tar.tar"
|
||||
Loading…
Reference in New Issue
Block a user