-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf1a253
commit 0d5fabe
Showing
10 changed files
with
453 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
build_from: | ||
aarch64: homeassistant/aarch64-base:latest | ||
amd64: homeassistant/amd64-base:latest | ||
armhf: homeassistant/armhf-base:latest | ||
armv7: homeassistant/armv7-base:latest | ||
i386: homeassistant/i386-base:latest | ||
|
||
aarch64: "ghcr.io/home-assistant/aarch64-base-python:" | ||
armv7: "ghcr.io/home-assistant/armv7-base-python:" | ||
armhf: "ghcr.io/home-assistant/armhf-base-python:" | ||
amd64: "ghcr.io/home-assistant/amd64-base-python:" | ||
i386: "ghcr.io/home-assistant/i386-base-python:" | ||
labels: | ||
org.opencontainers.image.title: "Home Assistant Add-on: Borg Backup" | ||
org.opencontainers.image.description: "Makes backup to remote or local borg repository" | ||
org.opencontainers.image.source: "https://github.com/bmanojlovic/home-assistant-borg-backup" | ||
org.opencontainers.image.licenses: "Apache License 2.0" | ||
args: | ||
CLI_VERSION: "4.23.0" | ||
CLI_VERSION: "4.36.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
#!/bin/bash | ||
function _log { | ||
D=$(date +"%Y%m%dT%H:%M:%S") | ||
echo -e $D "$@" | ||
} | ||
function log_error { | ||
_log "\e[0;31mERROR\e[0m : $@" | ||
exit -1 | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
# Logging functions | ||
function log_error() { | ||
printf '\e[31mERROR:\e[0m %s\n' "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
function log_warn { | ||
ISSUE=$(($ISSUE + 1 )) | ||
_log "\e[0;33mWARN\e[0m : $@" | ||
} | ||
function log_info { | ||
_log "\e[1;32mINFO\e[0m : $@" | ||
function log_warn() { | ||
printf '\e[33mWARN:\e[0m %s\n' "$*" >&2 | ||
((ISSUE++)) | ||
} | ||
|
||
function remote_exec { | ||
ssh -t $REMOTE_HOST "sh -lc \"set -e;$@\"" | ||
function log_info() { | ||
printf '\e[32mINFO:\e[0m %s\n' "$*" >&2 | ||
} | ||
|
||
####### CONFIGURATION ####### | ||
export MOUNT_POINT=/home/steki/addons | ||
export REMOTE_HOST=hassio | ||
#### END CONFIGURATION ###### | ||
|
||
function remote_exec() { | ||
ssh -t "${REMOTE_HOST}" "sh -lc \"set -e;$*\"" | ||
} | ||
|
||
L=$(LANG=C df -h ${MOUNT_POINT}|grep -c hassio) | ||
# Configuration | ||
readonly MOUNT_POINT="/home/steki/addons" | ||
readonly REMOTE_HOST="hassio" | ||
|
||
if [ $L -eq 1 ]; then | ||
#replace... | ||
log_info "already mounted" | ||
# Check if already mounted | ||
if LANG=C df -h "${MOUNT_POINT}" | grep -q hassio; then | ||
log_info "Already mounted" | ||
else | ||
log_info "mounting sshfs" | ||
sshfs ${REMOTE_HOST}:/addons ${MOUNT_POINT} || ( log_error "failed sshfs mount" ) | ||
log_info "Mounting sshfs" | ||
if ! sshfs "${REMOTE_HOST}:/addons" "${MOUNT_POINT}"; then | ||
log_error "Failed sshfs mount" | ||
fi | ||
fi | ||
|
||
rm -rf ${MOUNT_POINT}/borg-backup ||: | ||
mkdir -p ${MOUNT_POINT}/borg-backup | ||
cp -a * ${MOUNT_POINT}/borg-backup/ | ||
log_info "deployed source" | ||
|
||
CMD="ha addons reload" | ||
remote_exec "$CMD" | ||
|
||
CMD="ha addons rebuild local_borg-backup" | ||
remote_exec "$CMD" | ||
|
||
|
||
CMD="ha addons restart local_borg-backup" | ||
remote_exec "$CMD" | ||
|
||
# Clean and deploy | ||
rm -rf "${MOUNT_POINT}/borg-backup" || true | ||
mkdir -p "${MOUNT_POINT}/borg-backup" | ||
cp -a ./* "${MOUNT_POINT}/borg-backup/" | ||
log_info "Deployed source" | ||
|
||
# Execute Home Assistant commands | ||
for cmd in \ | ||
"ha addons reload" \ | ||
"ha addons rebuild local_borg-backup" \ | ||
"ha addons restart local_borg-backup"; do | ||
log_info "Executing: ${cmd}" | ||
remote_exec "${cmd}" | ||
done | ||
|
||
# Wait for restart and show logs | ||
sleep 2 | ||
CMD="ha addons logs local_borg-backup" | ||
remote_exec "$CMD" | ||
log_info "Showing logs" | ||
remote_exec "ha addons logs local_borg-backup" |
Oops, something went wrong.