From ec3534f7eeb368c7606c09ce2b2f8d10a2f4f2cd Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Fri, 6 May 2022 00:48:29 +0000 Subject: [PATCH 01/42] devcontainer --- .devcontainer/devcontainer.json | 48 ++++---- .github/stale.yml | 32 +++--- .github/workflows/publish.yaml | 56 +++++----- .github/workflows/test.yaml | 36 +++--- .vscode/tasks.json | 38 +++---- README.md | 34 +++--- remote-backup/CHANGELOG.md | 192 ++++++++++++++++---------------- remote-backup/DOCS.md | 18 +-- remote-backup/build.yaml | 14 +-- remote-backup/config.yaml | 140 +++++++++++------------ remote-backup/run.sh | 2 +- 11 files changed, 305 insertions(+), 305 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4bddb45..d113fc9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,24 +1,24 @@ -{ - "name": "Example devcontainer for add-on repositories", - "image": "ghcr.io/home-assistant/devcontainer:addons", - "appPort": ["7123:8123", "7357:4357"], - "postStartCommand": "bash devcontainer_bootstrap", - "runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"], - "containerEnv": { - "WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}" - }, - "extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode"], - "mounts": [ "type=volume,target=/var/lib/docker" ], - "settings": { - "terminal.integrated.profiles.linux": { - "zsh": { - "path": "/usr/bin/zsh" - } - }, - "terminal.integrated.defaultProfile.linux": "zsh", - "editor.formatOnPaste": false, - "editor.formatOnSave": true, - "editor.formatOnType": true, - "files.trimTrailingWhitespace": true - } -} +{ + "name": "Example devcontainer for add-on repositories", + "image": "ghcr.io/home-assistant/devcontainer:addons", + "appPort": ["7123:8123", "7357:4357"], + "postStartCommand": "bash devcontainer_bootstrap", + "runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"], + "containerEnv": { + "WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}" + }, + "extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode"], + "mounts": [ "type=volume,target=/var/lib/docker" ], + "settings": { + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "/usr/bin/zsh" + } + }, + "terminal.integrated.defaultProfile.linux": "zsh", + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true + } +} diff --git a/.github/stale.yml b/.github/stale.yml index 3b0f14a..d1d403e 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,17 +1,17 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 60 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 7 -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security -# Label to use when marking an issue as stale -staleLabel: stale -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable closeComment: false \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 2d809c8..21b9a59 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,29 +1,29 @@ -name: "Publish" - -on: - workflow_dispatch: - branches: - - master - release: - types: [published] - -jobs: - publish: - name: Publish - runs-on: ubuntu-latest - steps: - - name: Checkout the repository - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Publish - uses: home-assistant/builder@master - with: - args: | - --all \ - --target remote-backup \ - --docker-user ${{ secrets.DOCKERHUB_USERNAME }} \ +name: "Publish" + +on: + workflow_dispatch: + branches: + - master + release: + types: [published] + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Publish + uses: home-assistant/builder@master + with: + args: | + --all \ + --target remote-backup \ + --docker-user ${{ secrets.DOCKERHUB_USERNAME }} \ --docker-password ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 53f8d56..cac10bd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,19 +1,19 @@ -name: "Test" - -on: [push, pull_request] - -jobs: - build: - name: Test build - runs-on: ubuntu-latest - steps: - - name: Checkout the repository - uses: actions/checkout@v2 - - name: Test build - uses: home-assistant/builder@master - with: - args: | - --test \ - --all \ - --target remote-backup \ +name: "Test" + +on: [push, pull_request] + +jobs: + build: + name: Test build + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + - name: Test build + uses: home-assistant/builder@master + with: + args: | + --test \ + --all \ + --target remote-backup \ --docker-hub ikifar \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 36e373a..15f0f16 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,20 +1,20 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "Start Home Assistant", - "type": "shell", - "command": "supervisor_run", - "group": { - "kind": "test", - "isDefault": true - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, - "problemMatcher": [] - } - ] - } +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Start Home Assistant", + "type": "shell", + "command": "supervisor_run", + "group": { + "kind": "test", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [] + } + ] + } \ No newline at end of file diff --git a/README.md b/README.md index bcbc581..e8512be 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# Remote Backup -This add-on is a fork of the work of [carstenschroeder] which was originally created by [overkill32] -# Installation -This add-on can be added via my [Home Assistant Add-on repository](https://github.com/ikifar2012/ha-addons): - -[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fikifar2012%2Fha-addons) - -# [Documentation](https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config) - -# Support Me -[![Buy me a coffee][buymeacoffee-logo]][buymeacoffee] - -[buymeacoffee-logo]: https://cdn.buymeacoffee.com/buttons/default-black.png -[buymeacoffee]: https://www.buymeacoffee.com/mathesonstep -[overkill32]: https://github.com/overkill32/hassio-remote-backup -[carstenschroeder]: https://github.com/carstenschroeder/hassio-addons -[here]: https://www.home-assistant.io/hassio/installing_third_party_addons/ +# Remote Backup +This add-on is a fork of the work of [carstenschroeder] which was originally created by [overkill32] +# Installation +This add-on can be added via my [Home Assistant Add-on repository](https://github.com/ikifar2012/ha-addons): + +[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fikifar2012%2Fha-addons) + +# [Documentation](https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config) + +# Support Me +[![Buy me a coffee][buymeacoffee-logo]][buymeacoffee] + +[buymeacoffee-logo]: https://cdn.buymeacoffee.com/buttons/default-black.png +[buymeacoffee]: https://www.buymeacoffee.com/mathesonstep +[overkill32]: https://github.com/overkill32/hassio-remote-backup +[carstenschroeder]: https://github.com/carstenschroeder/hassio-addons +[here]: https://www.home-assistant.io/hassio/installing_third_party_addons/ diff --git a/remote-backup/CHANGELOG.md b/remote-backup/CHANGELOG.md index 25da9c9..42944b2 100644 --- a/remote-backup/CHANGELOG.md +++ b/remote-backup/CHANGELOG.md @@ -1,96 +1,96 @@ -# 2022.1.1 - -- Updated url in `config.yaml` -- Fixed `amd64` base image - -**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2022.1.0...2022.1.1 - -# 2022.1.0 - -- Converted to YAML -- Upgraded base image to 11.0.1 -- Moved docs to [addons.mathesonsteplock.ca](https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config) - -**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.12.0...2022.1.0 - -# 2021.12.0 - -- Upgraded base image to 11.0.0 - -**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.11.2...2021.12.0 - -# 2021.11.2 - -- Fix typo in rclone causing failure - -**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.11.1...2021.11.2 - -# 2021.11.1 - -- Added rsync exclude (#28) -- Made command line output more friendly -- Upgraded base image to 10.2.3 -- Switched to Github Actions - -**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.10.0...2021.11.1 - -# 2021.10.0 - -- Upgraded Base to 10.1.1 -- Upgraded Home Assistant CLI to 4.14.0 -- Changed from `snapshots` to `backups` (See Breaking Change #26) - -# 2021.9.0 - -- Upgraded Base to 10.0.2 -- 🎉 Solved issue #24 thanks to @hendrikma for pointing it out and @DubhAd for helping me solve it!!! 🎉 - -# 2021.8.0 - -- Upgraded Base to 10.0.1 - -# 2021.6.2 - -- Upgraded Base to 10.0.0 - -# 2021.6.1 - -- Upgraded Base to 9.2.2 - -# 2021.6.0 - -- Upgraded Base to 9.2.1 - -# 2021.5.2 - -- Upgraded Home Assistant CLI to 4.12.3 - -# 2021.5.1 - -- Upgraded Home Assistant CLI to 4.12.2 - -# 2021.5.0 - -- Added rclone -- Upgraded Base to 9.2.0 -- rsync now excludes all database files - -# 2021.4.1 - -- Removed extra `:` in $rsyncurl - -# 2021.4.0 - -- Changed snapshot date scheme `%Y-%m-%d %H-%M` to improve compatibility -- Added `custom_prefix` Allows you to change the name prefixing the date of the snapshot, by default this is set to `Automated backup` -- Added `friendly_name` Allows the snapshot to be renamed on the destination server to match the name in the Home Assistant UI -- Upgraded Base to 9.1.6 -- Upgraded Home Assistant CLI to 4.11.3 -- Reformatted code -- Addresses issue #13 - -# 2021.3.0 - -- Upgraded Home Assistant CLI to 4.11.0 -- Upgraded Base to 9.1.5 -- Changed versioning to match Home Assistant style +# 2022.1.1 + +- Updated url in `config.yaml` +- Fixed `amd64` base image + +**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2022.1.0...2022.1.1 + +# 2022.1.0 + +- Converted to YAML +- Upgraded base image to 11.0.1 +- Moved docs to [addons.mathesonsteplock.ca](https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config) + +**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.12.0...2022.1.0 + +# 2021.12.0 + +- Upgraded base image to 11.0.0 + +**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.11.2...2021.12.0 + +# 2021.11.2 + +- Fix typo in rclone causing failure + +**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.11.1...2021.11.2 + +# 2021.11.1 + +- Added rsync exclude (#28) +- Made command line output more friendly +- Upgraded base image to 10.2.3 +- Switched to Github Actions + +**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2021.10.0...2021.11.1 + +# 2021.10.0 + +- Upgraded Base to 10.1.1 +- Upgraded Home Assistant CLI to 4.14.0 +- Changed from `snapshots` to `backups` (See Breaking Change #26) + +# 2021.9.0 + +- Upgraded Base to 10.0.2 +- 🎉 Solved issue #24 thanks to @hendrikma for pointing it out and @DubhAd for helping me solve it!!! 🎉 + +# 2021.8.0 + +- Upgraded Base to 10.0.1 + +# 2021.6.2 + +- Upgraded Base to 10.0.0 + +# 2021.6.1 + +- Upgraded Base to 9.2.2 + +# 2021.6.0 + +- Upgraded Base to 9.2.1 + +# 2021.5.2 + +- Upgraded Home Assistant CLI to 4.12.3 + +# 2021.5.1 + +- Upgraded Home Assistant CLI to 4.12.2 + +# 2021.5.0 + +- Added rclone +- Upgraded Base to 9.2.0 +- rsync now excludes all database files + +# 2021.4.1 + +- Removed extra `:` in $rsyncurl + +# 2021.4.0 + +- Changed snapshot date scheme `%Y-%m-%d %H-%M` to improve compatibility +- Added `custom_prefix` Allows you to change the name prefixing the date of the snapshot, by default this is set to `Automated backup` +- Added `friendly_name` Allows the snapshot to be renamed on the destination server to match the name in the Home Assistant UI +- Upgraded Base to 9.1.6 +- Upgraded Home Assistant CLI to 4.11.3 +- Reformatted code +- Addresses issue #13 + +# 2021.3.0 + +- Upgraded Home Assistant CLI to 4.11.0 +- Upgraded Base to 9.1.5 +- Changed versioning to match Home Assistant style diff --git a/remote-backup/DOCS.md b/remote-backup/DOCS.md index 472a1a2..8647af6 100644 --- a/remote-backup/DOCS.md +++ b/remote-backup/DOCS.md @@ -1,10 +1,10 @@ -# Documentation - -Please visit the documentation at [addons.mathesonsteplock.ca](https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config) - -# Support Me - -[![Buy me a coffee][buymeacoffee-logo]][buymeacoffee] - -[buymeacoffee-logo]: https://cdn.buymeacoffee.com/buttons/default-black.png +# Documentation + +Please visit the documentation at [addons.mathesonsteplock.ca](https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config) + +# Support Me + +[![Buy me a coffee][buymeacoffee-logo]][buymeacoffee] + +[buymeacoffee-logo]: https://cdn.buymeacoffee.com/buttons/default-black.png [buymeacoffee]: https://www.buymeacoffee.com/mathesonstep \ No newline at end of file diff --git a/remote-backup/build.yaml b/remote-backup/build.yaml index b9027aa..0b53757 100644 --- a/remote-backup/build.yaml +++ b/remote-backup/build.yaml @@ -1,7 +1,7 @@ -squash: false -build_from: - aarch64: ghcr.io/hassio-addons/base/aarch64:11.0.1 - amd64: ghcr.io/hassio-addons/base/amd64:11.0.1 - armhf: ghcr.io/hassio-addons/base/armhf:11.0.1 - armv7: ghcr.io/hassio-addons/base/armv7:11.0.1 - i386: ghcr.io/hassio-addons/base/i386:11.0.1 +squash: false +build_from: + aarch64: ghcr.io/hassio-addons/base/aarch64:11.0.1 + amd64: ghcr.io/hassio-addons/base/amd64:11.0.1 + armhf: ghcr.io/hassio-addons/base/armhf:11.0.1 + armv7: ghcr.io/hassio-addons/base/armv7:11.0.1 + i386: ghcr.io/hassio-addons/base/i386:11.0.1 diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index f2247e8..6761c4b 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -1,70 +1,70 @@ -name: Remote Backup -version: '2022.1.1' -slug: remote_backup -description: Automatically create and backup HA backups using SCP -url: https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config -startup: once -image: ikifar/remote-backup-{arch} -boot: manual -arch: - - aarch64 - - amd64 - - armhf - - armv7 - - i386 -hassio_api: true -hassio_role: manager -map: - - config - - addons - - share - - ssl - - backup:rw -options: - ssh_enabled: true - friendly_name: true - custom_prefix: Automated backup - ssh_host: '' - ssh_port: 22 - ssh_user: '' - ssh_key: '' - remote_directory: '' - zip_password: '' - keep_local_backup: '' - rsync_enabled: false - rsync_verbose: false - rsync_host: '' - rsync_rootfolder: hassio-sync - rsync_exclude: '' - rsync_user: '' - rsync_password: '' - rclone_enabled: false - rclone_copy: false - rclone_sync: false - rclone_restore: false - rclone_remote: '' - rclone_remote_directory: '' -schema: - ssh_enabled: bool - friendly_name: bool - custom_prefix: str - ssh_host: str - ssh_port: int - ssh_user: str - ssh_key: str - remote_directory: str - zip_password: str - keep_local_backup: match(^(all|[+]?\d*)$) - rsync_enabled: bool - rsync_verbose: bool - rsync_host: str - rsync_rootfolder: str - rsync_exclude: str - rsync_user: str - rsync_password: str - rclone_enabled: bool - rclone_copy: bool - rclone_sync: bool - rclone_restore: bool - rclone_remote: str - rclone_remote_directory: str +name: Remote Backup +version: '2022.1.1' +slug: remote_backup +description: Automatically create and backup HA backups using SCP +url: https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config +startup: once +image: ikifar/remote-backup-{arch} +boot: manual +arch: + - aarch64 + - amd64 + - armhf + - armv7 + - i386 +hassio_api: true +hassio_role: manager +map: + - config + - addons + - share + - ssl + - backup:rw +options: + ssh_enabled: true + friendly_name: true + custom_prefix: Automated backup + ssh_host: '' + ssh_port: 22 + ssh_user: '' + ssh_key: '' + remote_directory: '' + zip_password: '' + keep_local_backup: '' + rsync_enabled: false + rsync_verbose: false + rsync_host: '' + rsync_rootfolder: hassio-sync + rsync_exclude: '' + rsync_user: '' + rsync_password: '' + rclone_enabled: false + rclone_copy: false + rclone_sync: false + rclone_restore: false + rclone_remote: '' + rclone_remote_directory: '' +schema: + ssh_enabled: bool + friendly_name: bool + custom_prefix: str + ssh_host: str + ssh_port: int + ssh_user: str + ssh_key: str + remote_directory: str + zip_password: str + keep_local_backup: match(^(all|[+]?\d*)$) + rsync_enabled: bool + rsync_verbose: bool + rsync_host: str + rsync_rootfolder: str + rsync_exclude: str + rsync_user: str + rsync_password: str + rclone_enabled: bool + rclone_copy: bool + rclone_sync: bool + rclone_restore: bool + rclone_remote: str + rclone_remote_directory: str diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 1a2d880..14fe41f 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -53,7 +53,7 @@ function add-ssh-key { chmod 600 "${HOME}/.ssh/config" chmod 644 "${HOME}/.ssh/id_rsa.pub" info "SSH key added" - fi + fi } function create-local-backup { From 394ee02d49121a87e09d7ac65bd3f89b10ebd687 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Fri, 6 May 2022 20:56:55 +0000 Subject: [PATCH 02/42] make shellcheck happy --- remote-backup/run.sh | 67 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 14fe41f..9bebcee 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -32,13 +32,13 @@ function warn { echo -e "\e[33m[warn] $*\e[39m"; } # create variables SSH_ID="/ssl/${SSH_KEY}" -SSH_ID=$(echo -n ${SSH_ID}) +SSH_ID=$(echo -n "${SSH_ID}") function add-ssh-key { - if [ "$SSH_ENABLED" = true ] ; then + if [ "${SSH_ENABLED}" = true ] ; then info "Adding SSH key" mkdir -p ~/.ssh - cp ${SSH_ID} ${HOME}/.ssh/id_rsa + cp "${SSH_ID}" "${HOME}"/.ssh/id_rsa chmod 600 "${HOME}/.ssh/id_rsa" ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub ( @@ -48,6 +48,7 @@ function add-ssh-key { echo " User ${SSH_USER}" echo " Port ${SSH_PORT}" echo " StrictHostKeyChecking no" + ) > "${HOME}/.ssh/config" chmod 600 "${HOME}/.ssh/config" @@ -66,7 +67,7 @@ function create-local-backup { function copy-backup-to-remote { if [ "$SSH_ENABLED" = true ] ; then - cd /backup/ + cd /backup/ || exit if [[ -z $ZIP_PASSWORD ]]; then warn "Copying ${slug}.tar to ${REMOTE_DIRECTORY} on ${SSH_HOST} using SCP" scp -F "${HOME}/.ssh/config" "${slug}.tar" remote:"${REMOTE_DIRECTORY}" @@ -77,8 +78,8 @@ function copy-backup-to-remote { scp -F "${HOME}/.ssh/config" "${slug}.zip" remote:"${REMOTE_DIRECTORY}" && rm "${slug}.zip" info "Backup copied to ${REMOTE_DIRECTORY}/${slug}.zip on ${SSH_HOST}" fi - if [ "$FRIENDLY_NAME" = true ] ; then - if [[ -z $ZIP_PASSWORD ]]; then + if [ "${FRIENDLY_NAME}" = true ] ; then + if [[ -z ${ZIP_PASSWORD} ]]; then warn "Renaming ${slug}.tar to ${name}.tar" ssh remote "mv \"${REMOTE_DIRECTORY}/${slug}.tar\" \"${REMOTE_DIRECTORY}/${name}.tar\"" info "Backup renamed to ${REMOTE_DIRECTORY}/${name}.tar on ${SSH_HOST}" @@ -94,57 +95,57 @@ function copy-backup-to-remote { function rsync_folders { - if [ "$RSYNC_ENABLED" = true ] ; then - rsyncurl="$RSYNC_USER@$RSYNC_HOST:$RSYNC_ROOTFOLDER" - if [ "$RSYNC_VERBOSE" = true ] ; then + if [ "${RSYNC_ENABLED}" = true ] ; then + rsyncurl="${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_ROOTFOLDER}" + if [ "${RSYNC_VERBOSE}" = true ] ; then FLAGS='-av' else FLAGS='-a' fi if [ -z "$RSYNC_EXCLUDE" ]; then warn "Syncing /config" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ $rsyncurl/config/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete info "/config sync complete" echo "" warn "Syncing /addons" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS /addons/ $rsyncurl/addons/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /addons/ "${rsyncurl}"/addons/ --delete info "/addons sync complete" echo "" warn "Syncing /backup" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS /backup/ $rsyncurl/backup/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /backup/ "${rsyncurl}"/backup/ --delete info "/backup sync complete" echo "" warn "Syncing /share" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS /share/ $rsyncurl/share/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /share/ "${rsyncurl}"/share/ --delete info "/share sync complete" echo "" warn "Syncing /ssl" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS /ssl/ $rsyncurl/ssl/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /ssl/ "${rsyncurl}"/ssl/ --delete info "/ssl sync complete" echo "" else - echo $RSYNC_EXCLUDE | tr -s ", " "\n" > /tmp/rsync_exclude.txt + echo "${RSYNC_EXCLUDE}" | tr -s ", " "\n" > /tmp/rsync_exclude.txt info "Files you excluded will be displayed below:" cat /tmp/rsync_exclude.txt info "Starting rsync" warn "Syncing /config" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ $rsyncurl/config/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete info "/config sync complete" echo "" warn "Syncing /addons" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /addons/ $rsyncurl/addons/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /addons/ "${rsyncurl}"/addons/ --delete info "/addons sync complete" echo "" warn "Syncing /backup" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /backup/ $rsyncurl/backup/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /backup/ "${rsyncurl}"/backup/ --delete info "/backup sync complete" echo "" warn "Syncing /share" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /share/ $rsyncurl/share/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /share/ "${rsyncurl}"/share/ --delete info "/share sync complete" echo "" warn "Syncing /ssl" - sshpass -p $RSYNC_PASSWORD rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /ssl/ $rsyncurl/ssl/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /ssl/ "${rsyncurl}"/ssl/ --delete info "/ssl sync complete" echo "" fi @@ -153,8 +154,8 @@ function rsync_folders { } function rclone_backups { - if [ "$RCLONE_ENABLED" = true ] ; then - cd /backup/ + if [ "${RCLONE_ENABLED}" = true ] ; then + cd /backup/ || exit mkdir -p ~/.config/rclone/ cp -a /ssl/rclone.conf ~/.config/rclone/rclone.conf echo "Starting rclone" @@ -162,28 +163,28 @@ function rclone_backups { if [ "$FRIENDLY_NAME" = true ] ; then if [[ -z $ZIP_PASSWORD ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${name}.tar" - rclone copyto ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".tar + rclone copyto "${slug}".tar "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}"/"${name}".tar info "Finished rclone copy" else warn "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${name}.zip" - rclone copyto ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".zip + rclone copyto "${slug}".zip "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}"/"${name}".zip info "Finished rclone copy" fi else if [[ -z $ZIP_PASSWORD ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${slug}.tar" - rclone copy ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} + rclone copy "${slug}".tar "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone copy" else warn "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${slug}.zip" - rclone copy ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} + rclone copy "${slug}".zip "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone copy" fi fi fi - if [ "$RCLONE_SYNC" = true ] ; then + if [ "${RCLONE_SYNC}" = true ] ; then warn "Syncing Backups" - rclone sync . ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} + rclone sync . "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone sync" fi if [ "$RCLONE_RESTORE" = true ] ; then @@ -191,7 +192,7 @@ function rclone_backups { RESTORENAME="restore-${DATEFORMAT}" mkdir -p "${RESTORENAME}" warn "Restoring Backups to ${RESTORENAME}" - rclone copyto ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} ${RESTORENAME}/ + rclone copyto "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" "${RESTORENAME}"/ info "Finished rclone restore" fi fi @@ -213,10 +214,10 @@ function delete-local-backup { head -n "${KEEP_LOCAL_BACKUP}" | tail -n 1 | xargs date -D "%Y-%m-%dT%T" +%s --date ) ha backups list --raw-json | jq -c .data.backups[] | while read backup; do - if [[ $(echo ${backup} | jq .date | xargs date -D "%Y-%m-%dT%T" +%s --date ) -lt ${last_date_to_keep} ]]; then - warn "Deleting local backup: $(echo ${backup} | jq -r .slug)" - ha backups remove "$(echo ${backup} | jq -r .slug)" - info "Finished deleting local backup: $(echo ${backup} | jq -r .slug)" + if [[ $(echo "${backup}" | jq .date | xargs date -D "%Y-%m-%dT%T" +%s --date ) -lt ${last_date_to_keep} ]]; then + warn "Deleting local backup: $(echo "${backup}" | jq -r .slug)" + ha backups remove "$(echo "${backup}" | jq -r .slug)" + info "Finished deleting local backup: $(echo "${backup}" | jq -r .slug)" fi done From df63408fd159c310f65efa51b16c49406de7452f Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Fri, 6 May 2022 21:04:38 +0000 Subject: [PATCH 03/42] more shellcheck fixes --- remote-backup/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 9bebcee..2f1de63 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -213,7 +213,7 @@ function delete-local-backup { last_date_to_keep=$(ha backups list --raw-json | jq .data.backups[].date | sort -r | \ head -n "${KEEP_LOCAL_BACKUP}" | tail -n 1 | xargs date -D "%Y-%m-%dT%T" +%s --date ) - ha backups list --raw-json | jq -c .data.backups[] | while read backup; do + ha backups list --raw-json | jq -c .data.backups[] | while read -r backup; do if [[ $(echo "${backup}" | jq .date | xargs date -D "%Y-%m-%dT%T" +%s --date ) -lt ${last_date_to_keep} ]]; then warn "Deleting local backup: $(echo "${backup}" | jq -r .slug)" ha backups remove "$(echo "${backup}" | jq -r .slug)" From 24918492b985247708c2fe121398654e339f6c1e Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Fri, 6 May 2022 21:09:40 +0000 Subject: [PATCH 04/42] devcontainer --- .devcontainer/devcontainer.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d113fc9..f78e5c3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "name": "Example devcontainer for add-on repositories", + "name": "Remote Backup Addon", "image": "ghcr.io/home-assistant/devcontainer:addons", "appPort": ["7123:8123", "7357:4357"], "postStartCommand": "bash devcontainer_bootstrap", @@ -7,7 +7,13 @@ "containerEnv": { "WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}" }, - "extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode"], + "extensions": [ + "timonwong.shellcheck", + "esbenp.prettier-vscode", + "GitHub.copilot", + "GitHub.vscode-pull-request-github", + "bierner.markdown-preview-github-styles" +], "mounts": [ "type=volume,target=/var/lib/docker" ], "settings": { "terminal.integrated.profiles.linux": { From b696562ea764c96054fd0616bb43be109a8b7b54 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Fri, 6 May 2022 21:41:55 +0000 Subject: [PATCH 05/42] add SSH_HOST_KEY_ALGORITHMS, solving issue Does Backup but doesn't save to remote server #37 --- remote-backup/config.yaml | 28 +++++++++++++++------------- remote-backup/run.sh | 5 ++++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index 6761c4b..65dd909 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -1,5 +1,5 @@ name: Remote Backup -version: '2022.1.1' +version: "2022.5.0" slug: remote_backup description: Automatically create and backup HA backups using SCP url: https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config @@ -24,26 +24,27 @@ options: ssh_enabled: true friendly_name: true custom_prefix: Automated backup - ssh_host: '' + ssh_host: "" ssh_port: 22 - ssh_user: '' - ssh_key: '' - remote_directory: '' - zip_password: '' - keep_local_backup: '' + ssh_user: "" + ssh_key: "" + ssh_host_key_algorithms: "" + remote_directory: "" + zip_password: "" + keep_local_backup: "" rsync_enabled: false rsync_verbose: false - rsync_host: '' + rsync_host: "" rsync_rootfolder: hassio-sync - rsync_exclude: '' - rsync_user: '' - rsync_password: '' + rsync_exclude: "" + rsync_user: "" + rsync_password: "" rclone_enabled: false rclone_copy: false rclone_sync: false rclone_restore: false - rclone_remote: '' - rclone_remote_directory: '' + rclone_remote: "" + rclone_remote_directory: "" schema: ssh_enabled: bool friendly_name: bool @@ -52,6 +53,7 @@ schema: ssh_port: int ssh_user: str ssh_key: str + ssh_host_key_algorithms: str remote_directory: str zip_password: str keep_local_backup: match(^(all|[+]?\d*)$) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 2f1de63..48cd1b8 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -8,6 +8,7 @@ SSH_HOST=$(bashio::config "ssh_host") SSH_PORT=$(bashio::config "ssh_port") SSH_USER=$(bashio::config "ssh_user") SSH_KEY=$(bashio::config "ssh_key") +SSH_HOST_KEY_ALGORITHMS=$(bashio::config "ssh_host_key_algorithms") REMOTE_DIRECTORY=$(bashio::config "remote_directory") ZIP_PASSWORD=$(bashio::config 'zip_password') KEEP_LOCAL_BACKUP=$(bashio::config 'keep_local_backup') @@ -48,7 +49,9 @@ function add-ssh-key { echo " User ${SSH_USER}" echo " Port ${SSH_PORT}" echo " StrictHostKeyChecking no" - + if [ -z "${SSH_HOST_KEY_ALGORITHMS}" ] ; then + echo " HostKeyAlgorithms ${SSH_HOST_KEY_ALGORITHMS}" + fi ) > "${HOME}/.ssh/config" chmod 600 "${HOME}/.ssh/config" From e41329805ff3e6b23c5cb3cbe2239e187c7049f3 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sat, 7 May 2022 02:55:39 +0000 Subject: [PATCH 06/42] switch to curly braces --- remote-backup/run.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 48cd1b8..97d5752 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -107,7 +107,7 @@ function rsync_folders { fi if [ -z "$RSYNC_EXCLUDE" ]; then warn "Syncing /config" - sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete info "/config sync complete" echo "" warn "Syncing /addons" @@ -132,23 +132,23 @@ function rsync_folders { cat /tmp/rsync_exclude.txt info "Starting rsync" warn "Syncing /config" - sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete info "/config sync complete" echo "" warn "Syncing /addons" - sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /addons/ "${rsyncurl}"/addons/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /addons/ "${rsyncurl}"/addons/ --delete info "/addons sync complete" echo "" warn "Syncing /backup" - sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /backup/ "${rsyncurl}"/backup/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /backup/ "${rsyncurl}"/backup/ --delete info "/backup sync complete" echo "" warn "Syncing /share" - sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /share/ "${rsyncurl}"/share/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /share/ "${rsyncurl}"/share/ --delete info "/share sync complete" echo "" warn "Syncing /ssl" - sshpass -p "${RSYNC_PASSWORD}" rsync $FLAGS --exclude-from='/tmp/rsync_exclude.txt' /ssl/ "${rsyncurl}"/ssl/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /ssl/ "${rsyncurl}"/ssl/ --delete info "/ssl sync complete" echo "" fi From bec785e7f2f27d9d99266c08a8c925435737400a Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sat, 7 May 2022 03:08:07 +0000 Subject: [PATCH 07/42] check if var is not empty --- remote-backup/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 97d5752..465f354 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -49,7 +49,7 @@ function add-ssh-key { echo " User ${SSH_USER}" echo " Port ${SSH_PORT}" echo " StrictHostKeyChecking no" - if [ -z "${SSH_HOST_KEY_ALGORITHMS}" ] ; then + if [ -n "${SSH_HOST_KEY_ALGORITHMS}" ] ; then echo " HostKeyAlgorithms ${SSH_HOST_KEY_ALGORITHMS}" fi ) > "${HOME}/.ssh/config" From b075cf588700f8c916349bcfd25bb391a6c7af4b Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 8 May 2022 16:09:58 -0400 Subject: [PATCH 08/42] bump version to 11.1.2 --- remote-backup/build.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/remote-backup/build.yaml b/remote-backup/build.yaml index 0b53757..6598c99 100644 --- a/remote-backup/build.yaml +++ b/remote-backup/build.yaml @@ -1,7 +1,7 @@ squash: false build_from: - aarch64: ghcr.io/hassio-addons/base/aarch64:11.0.1 - amd64: ghcr.io/hassio-addons/base/amd64:11.0.1 - armhf: ghcr.io/hassio-addons/base/armhf:11.0.1 - armv7: ghcr.io/hassio-addons/base/armv7:11.0.1 - i386: ghcr.io/hassio-addons/base/i386:11.0.1 + aarch64: ghcr.io/hassio-addons/base/aarch64:11.1.2 + amd64: ghcr.io/hassio-addons/base/amd64:11.1.2 + armhf: ghcr.io/hassio-addons/base/armhf:11.1.2 + armv7: ghcr.io/hassio-addons/base/armv7:11.1.2 + i386: ghcr.io/hassio-addons/base/i386:11.1.2 From 524be186a839932ec22a4f46dfe4bb14f33be180 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 8 May 2022 16:12:50 -0400 Subject: [PATCH 09/42] upgrade CLI --- remote-backup/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/Dockerfile b/remote-backup/Dockerfile index 8ec0916..b240262 100644 --- a/remote-backup/Dockerfile +++ b/remote-backup/Dockerfile @@ -17,7 +17,7 @@ RUN curl https://rclone.org/install.sh | bash # Hass.io CLI ARG BUILD_ARCH ARG CLI_VERSION -RUN wget -O /usr/bin/ha "https://github.com/home-assistant/cli/releases/download/4.14.0/ha_${BUILD_ARCH}" \ +RUN wget -O /usr/bin/ha "https://github.com/home-assistant/cli/releases/download/4.17.0/ha_${BUILD_ARCH}" \ && chmod a+x /usr/bin/ha # Copy data From 80f7d5fcafbc752c79ed8b5b17b2aa0b49271f6a Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 8 May 2022 17:28:30 -0400 Subject: [PATCH 10/42] Add options for partial backup --- remote-backup/config.yaml | 4 ++++ remote-backup/run.sh | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index 65dd909..f9695d4 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -29,6 +29,8 @@ options: ssh_user: "" ssh_key: "" ssh_host_key_algorithms: "" + include_folders: [] + include_addons: [] remote_directory: "" zip_password: "" keep_local_backup: "" @@ -54,6 +56,8 @@ schema: ssh_user: str ssh_key: str ssh_host_key_algorithms: str + include_folders: list + include_addons: list remote_directory: str zip_password: str keep_local_backup: match(^(all|[+]?\d*)$) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 465f354..2264654 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -9,6 +9,8 @@ SSH_PORT=$(bashio::config "ssh_port") SSH_USER=$(bashio::config "ssh_user") SSH_KEY=$(bashio::config "ssh_key") SSH_HOST_KEY_ALGORITHMS=$(bashio::config "ssh_host_key_algorithms") +INCLUDE_FOLDERS=$(bashio::config "include_folders") +INCLUDE_ADDONS=$(bashio::config "include_addons") REMOTE_DIRECTORY=$(bashio::config "remote_directory") ZIP_PASSWORD=$(bashio::config 'zip_password') KEEP_LOCAL_BACKUP=$(bashio::config 'keep_local_backup') @@ -63,7 +65,33 @@ function add-ssh-key { function create-local-backup { name="${CUSTOM_PREFIX} $(date +'%Y-%m-%d %H-%M')" warn "Creating local backup: \"${name}\"" - slug=$(ha backups new --raw-json --name="${name}" | jq --raw-output '.data.slug') + if [ -n "${INCLUDE_ADDONS}" ] ; then + info "Creating partial backup" + ADDONS="" + for addon in ${INCLUDE_ADDONS} ; do + ADDONS="${ADDONS} --addons=${addon}" + done + fi + if [ -n "${INCLUDE_FOLDERS}" ] ; then + info "Creating partial backup" + FOLDERS="" + for folder in ${INCLUDE_FOLDERS} ; do + FOLDERS="${FOLDERS} --folders=${folder}" + done + fi + if [ -n $FOLDERS ] && [ -n $ADDONS ] ; then + info "Creating partial backup" + slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" "${FOLDERS}" | jq --raw-output '.data.slug') + elif [ -n $FOLDERS ] ; then + info "Creating partial backup" + slug=$(ha backups new --raw-json --name="${name}" "${FOLDERS}" | jq --raw-output '.data.slug') + elif [ -n $ADDONS ] ; then + info "Creating partial backup" + slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" | jq --raw-output '.data.slug') + else + info "Creating full backup" + slug=$(ha backups new --raw-json --name="${name}" | jq --raw-output '.data.slug') + fi info "Backup created: ${slug}" } From b96244a6adaa266e6b3cae0a6860831ef9fa0e68 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 8 May 2022 23:01:32 -0400 Subject: [PATCH 11/42] switch to str --- remote-backup/config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index f9695d4..4a0f4cc 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -29,8 +29,8 @@ options: ssh_user: "" ssh_key: "" ssh_host_key_algorithms: "" - include_folders: [] - include_addons: [] + include_folders: "" + include_addons: "" remote_directory: "" zip_password: "" keep_local_backup: "" @@ -56,8 +56,8 @@ schema: ssh_user: str ssh_key: str ssh_host_key_algorithms: str - include_folders: list - include_addons: list + include_folders: str + include_addons: str remote_directory: str zip_password: str keep_local_backup: match(^(all|[+]?\d*)$) From fa5ed62748ccd17040a78c5c8d197b32b9c89b3f Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 8 May 2022 23:34:35 -0400 Subject: [PATCH 12/42] add info messages --- remote-backup/run.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 2264654..6baa4e1 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -69,6 +69,7 @@ function create-local-backup { info "Creating partial backup" ADDONS="" for addon in ${INCLUDE_ADDONS} ; do + info "Including ${addon}" ADDONS="${ADDONS} --addons=${addon}" done fi @@ -76,17 +77,21 @@ function create-local-backup { info "Creating partial backup" FOLDERS="" for folder in ${INCLUDE_FOLDERS} ; do + info "Including ${folder}" FOLDERS="${FOLDERS} --folders=${folder}" done fi if [ -n $FOLDERS ] && [ -n $ADDONS ] ; then info "Creating partial backup" + info "Including ${FOLDERS} and ${ADDONS}" slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" "${FOLDERS}" | jq --raw-output '.data.slug') elif [ -n $FOLDERS ] ; then info "Creating partial backup" + info "Including ${FOLDERS}" slug=$(ha backups new --raw-json --name="${name}" "${FOLDERS}" | jq --raw-output '.data.slug') elif [ -n $ADDONS ] ; then info "Creating partial backup" + info "Including ${ADDONS}" slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" | jq --raw-output '.data.slug') else info "Creating full backup" From b333d55fc43864da23855d98795c8c8bdca43018 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 00:01:55 -0400 Subject: [PATCH 13/42] bugs must be squashed --- remote-backup/run.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 6baa4e1..320da71 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -63,11 +63,13 @@ function add-ssh-key { } function create-local-backup { + # Bind variables + FOLDERS="" + ADDONS="" name="${CUSTOM_PREFIX} $(date +'%Y-%m-%d %H-%M')" warn "Creating local backup: \"${name}\"" if [ -n "${INCLUDE_ADDONS}" ] ; then info "Creating partial backup" - ADDONS="" for addon in ${INCLUDE_ADDONS} ; do info "Including ${addon}" ADDONS="${ADDONS} --addons=${addon}" @@ -75,21 +77,20 @@ function create-local-backup { fi if [ -n "${INCLUDE_FOLDERS}" ] ; then info "Creating partial backup" - FOLDERS="" for folder in ${INCLUDE_FOLDERS} ; do - info "Including ${folder}" - FOLDERS="${FOLDERS} --folders=${folder}" + info "Including ${folder}" + FOLDERS="${FOLDERS} --folders=${folder}" done fi - if [ -n $FOLDERS ] && [ -n $ADDONS ] ; then + if [ -n "${FOLDERS}" ] && [ -n "${ADDONS}" ] ; then info "Creating partial backup" info "Including ${FOLDERS} and ${ADDONS}" slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" "${FOLDERS}" | jq --raw-output '.data.slug') - elif [ -n $FOLDERS ] ; then + elif [ -n "${FOLDERS}" ] ; then info "Creating partial backup" info "Including ${FOLDERS}" slug=$(ha backups new --raw-json --name="${name}" "${FOLDERS}" | jq --raw-output '.data.slug') - elif [ -n $ADDONS ] ; then + elif [ -n "${ADDONS}" ] ; then info "Creating partial backup" info "Including ${ADDONS}" slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" | jq --raw-output '.data.slug') @@ -104,7 +105,7 @@ function copy-backup-to-remote { if [ "$SSH_ENABLED" = true ] ; then cd /backup/ || exit - if [[ -z $ZIP_PASSWORD ]]; then + if [[ -z "${ZIP_PASSWORD}" ]]; then warn "Copying ${slug}.tar to ${REMOTE_DIRECTORY} on ${SSH_HOST} using SCP" scp -F "${HOME}/.ssh/config" "${slug}.tar" remote:"${REMOTE_DIRECTORY}" info "Backup copied to ${REMOTE_DIRECTORY}/${slug}.tar on ${SSH_HOST}" @@ -115,7 +116,7 @@ function copy-backup-to-remote { info "Backup copied to ${REMOTE_DIRECTORY}/${slug}.zip on ${SSH_HOST}" fi if [ "${FRIENDLY_NAME}" = true ] ; then - if [[ -z ${ZIP_PASSWORD} ]]; then + if [[ -z "${ZIP_PASSWORD} " ]]; then warn "Renaming ${slug}.tar to ${name}.tar" ssh remote "mv \"${REMOTE_DIRECTORY}/${slug}.tar\" \"${REMOTE_DIRECTORY}/${name}.tar\"" info "Backup renamed to ${REMOTE_DIRECTORY}/${name}.tar on ${SSH_HOST}" @@ -138,7 +139,7 @@ function rsync_folders { else FLAGS='-a' fi - if [ -z "$RSYNC_EXCLUDE" ]; then + if [ -z "${RSYNC_EXCLUDE}" ]; then warn "Syncing /config" sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete info "/config sync complete" @@ -207,7 +208,7 @@ function rclone_backups { info "Finished rclone copy" fi else - if [[ -z $ZIP_PASSWORD ]]; then + if [[ -z "${ZIP_PASSWORD}" ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${slug}.tar" rclone copy "${slug}".tar "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone copy" @@ -223,7 +224,7 @@ function rclone_backups { rclone sync . "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone sync" fi - if [ "$RCLONE_RESTORE" = true ] ; then + if [ "${RCLONE_RESTORE}" = true ] ; then DATEFORMAT=$(date +%F) RESTORENAME="restore-${DATEFORMAT}" mkdir -p "${RESTORENAME}" @@ -239,9 +240,9 @@ function delete-local-backup { ha backups reload - if [[ ${KEEP_LOCAL_BACKUP} == "all" ]]; then + if [[ "${KEEP_LOCAL_BACKUP}" == "all" ]]; then : - elif [[ -z ${KEEP_LOCAL_BACKUP} ]]; then + elif [[ -z "${KEEP_LOCAL_BACKUP}" ]]; then warn "Deleting local backup: ${slug}" ha backups remove "${slug}" else From 842e3b29541682d088cb852d07ab6c6c7b2f9e6b Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 00:33:36 -0400 Subject: [PATCH 14/42] fixes --- remote-backup/run.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 320da71..bb9628c 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -41,7 +41,7 @@ function add-ssh-key { if [ "${SSH_ENABLED}" = true ] ; then info "Adding SSH key" mkdir -p ~/.ssh - cp "${SSH_ID}" "${HOME}"/.ssh/id_rsa + cp ${SSH_ID} ${HOME}/.ssh/id_rsa chmod 600 "${HOME}/.ssh/id_rsa" ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub ( @@ -85,18 +85,18 @@ function create-local-backup { if [ -n "${FOLDERS}" ] && [ -n "${ADDONS}" ] ; then info "Creating partial backup" info "Including ${FOLDERS} and ${ADDONS}" - slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" "${FOLDERS}" | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name=${name} ${ADDONS} ${FOLDERS} | jq --raw-output '.data.slug') elif [ -n "${FOLDERS}" ] ; then info "Creating partial backup" info "Including ${FOLDERS}" - slug=$(ha backups new --raw-json --name="${name}" "${FOLDERS}" | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name=${name} ${FOLDERS} | jq --raw-output '.data.slug') elif [ -n "${ADDONS}" ] ; then info "Creating partial backup" info "Including ${ADDONS}" - slug=$(ha backups new --raw-json --name="${name}" "${ADDONS}" | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name=${name} ${ADDONS} | jq --raw-output '.data.slug') else info "Creating full backup" - slug=$(ha backups new --raw-json --name="${name}" | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name=${name} | jq --raw-output '.data.slug') fi info "Backup created: ${slug}" } @@ -141,48 +141,48 @@ function rsync_folders { fi if [ -z "${RSYNC_EXCLUDE}" ]; then warn "Syncing /config" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ ${rsyncurl}/config/ --delete info "/config sync complete" echo "" warn "Syncing /addons" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /addons/ "${rsyncurl}"/addons/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /addons/ ${rsyncurl}/addons/ --delete info "/addons sync complete" echo "" warn "Syncing /backup" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /backup/ "${rsyncurl}"/backup/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /backup/ ${rsyncurl}/backup/ --delete info "/backup sync complete" echo "" warn "Syncing /share" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /share/ "${rsyncurl}"/share/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /share/ "${rsyncurl}"/share/ --delete info "/share sync complete" echo "" warn "Syncing /ssl" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /ssl/ "${rsyncurl}"/ssl/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /ssl/ ${rsyncurl}/ssl/ --delete info "/ssl sync complete" echo "" else - echo "${RSYNC_EXCLUDE}" | tr -s ", " "\n" > /tmp/rsync_exclude.txt + echo ${RSYNC_EXCLUDE} | tr -s ", " "\n" > /tmp/rsync_exclude.txt info "Files you excluded will be displayed below:" cat /tmp/rsync_exclude.txt info "Starting rsync" warn "Syncing /config" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete info "/config sync complete" echo "" warn "Syncing /addons" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /addons/ "${rsyncurl}"/addons/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /addons/ ${rsyncurl}/addons/ --delete info "/addons sync complete" echo "" warn "Syncing /backup" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /backup/ "${rsyncurl}"/backup/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /backup/ ${rsyncurl}/backup/ --delete info "/backup sync complete" echo "" warn "Syncing /share" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /share/ "${rsyncurl}"/share/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /share/ ${rsyncurl}/share/ --delete info "/share sync complete" echo "" warn "Syncing /ssl" - sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /ssl/ "${rsyncurl}"/ssl/ --delete + sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /ssl/ ${rsyncurl}/ssl/ --delete info "/ssl sync complete" echo "" fi @@ -200,21 +200,21 @@ function rclone_backups { if [ "$FRIENDLY_NAME" = true ] ; then if [[ -z $ZIP_PASSWORD ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${name}.tar" - rclone copyto "${slug}".tar "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}"/"${name}".tar + rclone copyto "${slug}".tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".tar info "Finished rclone copy" else warn "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${name}.zip" - rclone copyto "${slug}".zip "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}"/"${name}".zip + rclone copyto "${slug}".zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".zip info "Finished rclone copy" fi else if [[ -z "${ZIP_PASSWORD}" ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${slug}.tar" - rclone copy "${slug}".tar "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" + rclone copy ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} info "Finished rclone copy" else warn "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${slug}.zip" - rclone copy "${slug}".zip "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" + rclone copy ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} info "Finished rclone copy" fi fi @@ -229,7 +229,7 @@ function rclone_backups { RESTORENAME="restore-${DATEFORMAT}" mkdir -p "${RESTORENAME}" warn "Restoring Backups to ${RESTORENAME}" - rclone copyto "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" "${RESTORENAME}"/ + rclone copyto ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} ${RESTORENAME}/ info "Finished rclone restore" fi fi From fdcf1b78f8ad1ceba95689e61a6141c688c3b183 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 00:38:55 -0400 Subject: [PATCH 15/42] more fixes --- remote-backup/config.yaml | 53 +++++++++++++++++++-------------------- remote-backup/run.sh | 4 +-- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index 4a0f4cc..dfcc4e9 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -4,7 +4,6 @@ slug: remote_backup description: Automatically create and backup HA backups using SCP url: https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config startup: once -image: ikifar/remote-backup-{arch} boot: manual arch: - aarch64 @@ -48,29 +47,29 @@ options: rclone_remote: "" rclone_remote_directory: "" schema: - ssh_enabled: bool - friendly_name: bool - custom_prefix: str - ssh_host: str - ssh_port: int - ssh_user: str - ssh_key: str - ssh_host_key_algorithms: str - include_folders: str - include_addons: str - remote_directory: str - zip_password: str - keep_local_backup: match(^(all|[+]?\d*)$) - rsync_enabled: bool - rsync_verbose: bool - rsync_host: str - rsync_rootfolder: str - rsync_exclude: str - rsync_user: str - rsync_password: str - rclone_enabled: bool - rclone_copy: bool - rclone_sync: bool - rclone_restore: bool - rclone_remote: str - rclone_remote_directory: str + ssh_enabled: bool? + friendly_name: bool? + custom_prefix: str? + ssh_host: str? + ssh_port: int? + ssh_user: str? + ssh_key: str? + ssh_host_key_algorithms: str? + include_folders: str? + include_addons: str? + remote_directory: str? + zip_password: str? + keep_local_backup: int? + rsync_enabled: bool? + rsync_verbose: bool? + rsync_host: str? + rsync_rootfolder: str? + rsync_exclude: str? + rsync_user: str? + rsync_password: str? + rclone_enabled: bool? + rclone_copy: bool? + rclone_sync: bool? + rclone_restore: bool? + rclone_remote: str? + rclone_remote_directory: str? diff --git a/remote-backup/run.sh b/remote-backup/run.sh index bb9628c..ed8c7d6 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -200,11 +200,11 @@ function rclone_backups { if [ "$FRIENDLY_NAME" = true ] ; then if [[ -z $ZIP_PASSWORD ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${name}.tar" - rclone copyto "${slug}".tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".tar + rclone copyto ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".tar info "Finished rclone copy" else warn "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${name}.zip" - rclone copyto "${slug}".zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".zip + rclone copyto ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".zip info "Finished rclone copy" fi else From 4fbac53013be01691b590ce8f8262907eb9bfe0e Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 00:40:28 -0400 Subject: [PATCH 16/42] more cleanup --- remote-backup/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index ed8c7d6..6b66fbd 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -221,7 +221,7 @@ function rclone_backups { fi if [ "${RCLONE_SYNC}" = true ] ; then warn "Syncing Backups" - rclone sync . "${RCLONE_REMOTE}":"${RCLONE_REMOTE_DIRECTORY}" + rclone sync . ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} info "Finished rclone sync" fi if [ "${RCLONE_RESTORE}" = true ] ; then From 210ef2fb0611040c38a329cab0b7d5abd3ffcbfd Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 00:44:31 -0400 Subject: [PATCH 17/42] fix typo --- remote-backup/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 6b66fbd..25c8bfe 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -116,7 +116,7 @@ function copy-backup-to-remote { info "Backup copied to ${REMOTE_DIRECTORY}/${slug}.zip on ${SSH_HOST}" fi if [ "${FRIENDLY_NAME}" = true ] ; then - if [[ -z "${ZIP_PASSWORD} " ]]; then + if [[ -z "${ZIP_PASSWORD}" ]]; then warn "Renaming ${slug}.tar to ${name}.tar" ssh remote "mv \"${REMOTE_DIRECTORY}/${slug}.tar\" \"${REMOTE_DIRECTORY}/${name}.tar\"" info "Backup renamed to ${REMOTE_DIRECTORY}/${name}.tar on ${SSH_HOST}" From cce0e400e07a74fa9dc93400c9954c7b2bbe2a2e Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 00:50:45 -0400 Subject: [PATCH 18/42] quote name --- remote-backup/run.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 25c8bfe..8d2c11a 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -85,18 +85,18 @@ function create-local-backup { if [ -n "${FOLDERS}" ] && [ -n "${ADDONS}" ] ; then info "Creating partial backup" info "Including ${FOLDERS} and ${ADDONS}" - slug=$(ha backups new --raw-json --name=${name} ${ADDONS} ${FOLDERS} | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name="${name}" ${ADDONS} ${FOLDERS} | jq --raw-output '.data.slug') elif [ -n "${FOLDERS}" ] ; then info "Creating partial backup" info "Including ${FOLDERS}" - slug=$(ha backups new --raw-json --name=${name} ${FOLDERS} | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name="${name}" ${FOLDERS} | jq --raw-output '.data.slug') elif [ -n "${ADDONS}" ] ; then info "Creating partial backup" info "Including ${ADDONS}" - slug=$(ha backups new --raw-json --name=${name} ${ADDONS} | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name="${name}" ${ADDONS} | jq --raw-output '.data.slug') else info "Creating full backup" - slug=$(ha backups new --raw-json --name=${name} | jq --raw-output '.data.slug') + slug=$(ha backups new --raw-json --name="${name}" | jq --raw-output '.data.slug') fi info "Backup created: ${slug}" } From 5dde76d3e80f31f844a0dddd6721883aa83a540e Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 01:01:36 -0400 Subject: [PATCH 19/42] single quote --- remote-backup/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index dfcc4e9..f05fe05 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -1,5 +1,5 @@ name: Remote Backup -version: "2022.5.0" +version: '2022.5.0' slug: remote_backup description: Automatically create and backup HA backups using SCP url: https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config From a7900874e02b8a8337d83936267034179fc19286 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Mon, 9 May 2022 01:06:10 -0400 Subject: [PATCH 20/42] fix image --- remote-backup/config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index f05fe05..a598482 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -2,6 +2,7 @@ name: Remote Backup version: '2022.5.0' slug: remote_backup description: Automatically create and backup HA backups using SCP +image: ikifar/remote-backup-{arch} url: https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config startup: once boot: manual From 51d0a0b104ed868a849c80218e50cebcb89a00f8 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Tue, 10 May 2022 00:10:23 +0000 Subject: [PATCH 21/42] fixing qoutes --- remote-backup/run.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 8d2c11a..06da8d2 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -41,7 +41,7 @@ function add-ssh-key { if [ "${SSH_ENABLED}" = true ] ; then info "Adding SSH key" mkdir -p ~/.ssh - cp ${SSH_ID} ${HOME}/.ssh/id_rsa + cp "${SSH_ID}" "${HOME}"/.ssh/id_rsa chmod 600 "${HOME}/.ssh/id_rsa" ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub ( @@ -141,48 +141,48 @@ function rsync_folders { fi if [ -z "${RSYNC_EXCLUDE}" ]; then warn "Syncing /config" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ ${rsyncurl}/config/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}/config/" --delete info "/config sync complete" echo "" warn "Syncing /addons" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /addons/ ${rsyncurl}/addons/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /addons/ "${rsyncurl}/addons/" --delete info "/addons sync complete" echo "" warn "Syncing /backup" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /backup/ ${rsyncurl}/backup/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /backup/ "${rsyncurl}/backup/" --delete info "/backup sync complete" echo "" warn "Syncing /share" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /share/ "${rsyncurl}"/share/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /share/ "${rsyncurl}/share/" --delete info "/share sync complete" echo "" warn "Syncing /ssl" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} /ssl/ ${rsyncurl}/ssl/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} /ssl/ "${rsyncurl}/ssl/" --delete info "/ssl sync complete" echo "" else - echo ${RSYNC_EXCLUDE} | tr -s ", " "\n" > /tmp/rsync_exclude.txt + echo "${RSYNC_EXCLUDE}" | tr -s ", " "\n" > /tmp/rsync_exclude.txt info "Files you excluded will be displayed below:" cat /tmp/rsync_exclude.txt info "Starting rsync" warn "Syncing /config" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}"/config/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ "${rsyncurl}/config/" --delete info "/config sync complete" echo "" warn "Syncing /addons" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /addons/ ${rsyncurl}/addons/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /addons/ "${rsyncurl}/addons/" --delete info "/addons sync complete" echo "" warn "Syncing /backup" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /backup/ ${rsyncurl}/backup/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /backup/ "${rsyncurl}/backup/" --delete info "/backup sync complete" echo "" warn "Syncing /share" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /share/ ${rsyncurl}/share/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /share/ "${rsyncurl}/share/" --delete info "/share sync complete" echo "" warn "Syncing /ssl" - sshpass -p ${RSYNC_PASSWORD} rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /ssl/ ${rsyncurl}/ssl/ --delete + sshpass -p "${RSYNC_PASSWORD}" rsync ${FLAGS} --exclude-from='/tmp/rsync_exclude.txt' /ssl/ "${rsyncurl}/ssl/" --delete info "/ssl sync complete" echo "" fi @@ -200,28 +200,28 @@ function rclone_backups { if [ "$FRIENDLY_NAME" = true ] ; then if [[ -z $ZIP_PASSWORD ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${name}.tar" - rclone copyto ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".tar + rclone copyto "${slug}.tar" "${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/${name}".tar info "Finished rclone copy" else warn "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${name}.zip" - rclone copyto ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".zip + rclone copyto "${slug}.zip" "${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/${name}".zip info "Finished rclone copy" fi else if [[ -z "${ZIP_PASSWORD}" ]]; then warn "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${slug}.tar" - rclone copy ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} + rclone copy "${slug}.tar" "${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone copy" else warn "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${slug}.zip" - rclone copy ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} + rclone copy "${slug}.zip" "${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone copy" fi fi fi if [ "${RCLONE_SYNC}" = true ] ; then warn "Syncing Backups" - rclone sync . ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} + rclone sync . "${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}" info "Finished rclone sync" fi if [ "${RCLONE_RESTORE}" = true ] ; then @@ -229,7 +229,7 @@ function rclone_backups { RESTORENAME="restore-${DATEFORMAT}" mkdir -p "${RESTORENAME}" warn "Restoring Backups to ${RESTORENAME}" - rclone copyto ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} ${RESTORENAME}/ + rclone copyto "${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} ${RESTORENAME}/" info "Finished rclone restore" fi fi From 766517ce568cff0f39b7f7c0b8a6d47382e6ef37 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Tue, 10 May 2022 01:36:12 +0000 Subject: [PATCH 22/42] change include to exclude --- remote-backup/config.yaml | 10 +++++----- remote-backup/run.sh | 36 ++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index a598482..db5b07f 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -1,5 +1,5 @@ name: Remote Backup -version: '2022.5.0' +version: "2022.5.0" slug: remote_backup description: Automatically create and backup HA backups using SCP image: ikifar/remote-backup-{arch} @@ -29,8 +29,8 @@ options: ssh_user: "" ssh_key: "" ssh_host_key_algorithms: "" - include_folders: "" - include_addons: "" + exclude_folders: "" + exclude_addons: "" remote_directory: "" zip_password: "" keep_local_backup: "" @@ -56,8 +56,8 @@ schema: ssh_user: str? ssh_key: str? ssh_host_key_algorithms: str? - include_folders: str? - include_addons: str? + exclude_folders: str? + exclude_addons: str? remote_directory: str? zip_password: str? keep_local_backup: int? diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 06da8d2..5fdebbf 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -9,8 +9,8 @@ SSH_PORT=$(bashio::config "ssh_port") SSH_USER=$(bashio::config "ssh_user") SSH_KEY=$(bashio::config "ssh_key") SSH_HOST_KEY_ALGORITHMS=$(bashio::config "ssh_host_key_algorithms") -INCLUDE_FOLDERS=$(bashio::config "include_folders") -INCLUDE_ADDONS=$(bashio::config "include_addons") +EXCLUDE_FOLDERS=$(bashio::config "exclude_folders") +EXCLUDE_ADDONS=$(bashio::config "exclude_addons") REMOTE_DIRECTORY=$(bashio::config "remote_directory") ZIP_PASSWORD=$(bashio::config 'zip_password') KEEP_LOCAL_BACKUP=$(bashio::config 'keep_local_backup') @@ -66,20 +66,36 @@ function create-local-backup { # Bind variables FOLDERS="" ADDONS="" + INSTALLED_ADDONS=$(bashio::addons.installed) + BASE_FOLDERS=$(ls /) + echo "${INSTALLED_ADDONS}" name="${CUSTOM_PREFIX} $(date +'%Y-%m-%d %H-%M')" warn "Creating local backup: \"${name}\"" - if [ -n "${INCLUDE_ADDONS}" ] ; then + if [ -n "${EXCLUDE_ADDONS}" ] ; then info "Creating partial backup" - for addon in ${INCLUDE_ADDONS} ; do - info "Including ${addon}" - ADDONS="${ADDONS} --addons=${addon}" + for addon in ${EXCLUDE_ADDONS} ; do + for installed_addon in ${INSTALLED_ADDONS} ; do + if [ "${addon}" = "${installed_addon}" ] ; then + warn "Excluding addon: \"${addon}\"" + else + info "Including ${addon}" + ADDONS="${ADDONS} --addons=${addon}" + fi + done + done fi - if [ -n "${INCLUDE_FOLDERS}" ] ; then + if [ -n "${EXCLUDE_FOLDERS}" ] ; then info "Creating partial backup" - for folder in ${INCLUDE_FOLDERS} ; do - info "Including ${folder}" - FOLDERS="${FOLDERS} --folders=${folder}" + for folder in ${EXCLUDE_FOLDERS} ; do + for base_folder in ${BASE_FOLDERS} ; do + if [ "${folder}" = "${base_folder}" ] ; then + warn "Excluding folder: \"${folder}\"" + else + info "Including ${folder}" + FOLDERS="${FOLDERS} --folders=${folder}" + fi + done done fi if [ -n "${FOLDERS}" ] && [ -n "${ADDONS}" ] ; then From 691b75eb7464bc447f49bddb658f3d686f5df2b1 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Tue, 10 May 2022 03:21:07 +0000 Subject: [PATCH 23/42] Fix Excludes --- remote-backup/run.sh | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 5fdebbf..0f7b440 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bashio - +set -x # parse inputs from options SSH_ENABLED=$(bashio::config "ssh_enabled") FRIENDLY_NAME=$(bashio::config "friendly_name") @@ -66,36 +66,30 @@ function create-local-backup { # Bind variables FOLDERS="" ADDONS="" + BASE_FOLDERS="addons/local homeassistant media share ssl" INSTALLED_ADDONS=$(bashio::addons.installed) - BASE_FOLDERS=$(ls /) - echo "${INSTALLED_ADDONS}" name="${CUSTOM_PREFIX} $(date +'%Y-%m-%d %H-%M')" warn "Creating local backup: \"${name}\"" - if [ -n "${EXCLUDE_ADDONS}" ] ; then + if [ -n "${EXCLUDE_ADDONS}" ] || [ -n "${EXCLUDE_FOLDERS}" ] ; then info "Creating partial backup" - for addon in ${EXCLUDE_ADDONS} ; do - for installed_addon in ${INSTALLED_ADDONS} ; do - if [ "${addon}" = "${installed_addon}" ] ; then - warn "Excluding addon: \"${addon}\"" + for addon in ${INSTALLED_ADDONS} ; do + for excluded_addon in ${EXCLUDE_ADDONS} ; do + if [ "${addon}" = "${excluded_addon}" ] ; then + warn "Excluding addon: ${addon}" else - info "Including ${addon}" - ADDONS="${ADDONS} --addons=${addon}" - fi - done - + ADDONS="${ADDONS}--addons=${addon} " + fi + done done - fi - if [ -n "${EXCLUDE_FOLDERS}" ] ; then info "Creating partial backup" for folder in ${EXCLUDE_FOLDERS} ; do - for base_folder in ${BASE_FOLDERS} ; do - if [ "${folder}" = "${base_folder}" ] ; then - warn "Excluding folder: \"${folder}\"" - else - info "Including ${folder}" - FOLDERS="${FOLDERS} --folders=${folder}" - fi - done + for base_folder in ${BASE_FOLDERS} ; do + if [ "${folder}" = "${base_folder}" ] ; then + warn "Excluding folder: ${folder}" + else + FOLDERS="${FOLDERS}--folders=${folder} " + fi + done done fi if [ -n "${FOLDERS}" ] && [ -n "${ADDONS}" ] ; then From 6ef6d6d399a46992ebee407237493653084c495f Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Tue, 10 May 2022 03:34:48 +0000 Subject: [PATCH 24/42] remove options used for testing --- remote-backup/run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 0f7b440..b9ee0d4 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bashio -set -x # parse inputs from options SSH_ENABLED=$(bashio::config "ssh_enabled") FRIENDLY_NAME=$(bashio::config "friendly_name") From b2aae7af1d6a096ed91a760f0e1bef94ae8c9218 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Tue, 10 May 2022 04:06:36 +0000 Subject: [PATCH 25/42] rework logic --- remote-backup/run.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index b9ee0d4..4d70baa 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -80,13 +80,12 @@ function create-local-backup { fi done done - info "Creating partial backup" - for folder in ${EXCLUDE_FOLDERS} ; do - for base_folder in ${BASE_FOLDERS} ; do - if [ "${folder}" = "${base_folder}" ] ; then + for folder in ${BASE_FOLDERS} ; do + for excluded_folder in ${EXCLUDE_FOLDERS} ; do + if [ "${folder}" = "${excluded_folder}" ] ; then warn "Excluding folder: ${folder}" - else - FOLDERS="${FOLDERS}--folders=${folder} " + else + FOLDERS="${FOLDERS}--folders=${folder} " fi done done From 0babd40cc68679480cc92b40156f3c4dc967528e Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Tue, 10 May 2022 21:41:04 +0000 Subject: [PATCH 26/42] add debug --- remote-backup/config.yaml | 2 ++ remote-backup/run.sh | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index db5b07f..11e1195 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -21,6 +21,7 @@ map: - ssl - backup:rw options: + debug: false ssh_enabled: true friendly_name: true custom_prefix: Automated backup @@ -48,6 +49,7 @@ options: rclone_remote: "" rclone_remote_directory: "" schema: + debug: bool? ssh_enabled: bool? friendly_name: bool? custom_prefix: str? diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 4d70baa..fe5cfdd 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bashio # parse inputs from options +DEBUG=$(bashio::config 'debug') SSH_ENABLED=$(bashio::config "ssh_enabled") FRIENDLY_NAME=$(bashio::config "friendly_name") CUSTOM_PREFIX=$(bashio::config "custom_prefix") @@ -92,7 +93,9 @@ function create-local-backup { fi if [ -n "${FOLDERS}" ] && [ -n "${ADDONS}" ] ; then info "Creating partial backup" - info "Including ${FOLDERS} and ${ADDONS}" + if [ "${DEBUG}" = true ] ; then + warn "Including ${FOLDERS} and ${ADDONS}" + fi slug=$(ha backups new --raw-json --name="${name}" ${ADDONS} ${FOLDERS} | jq --raw-output '.data.slug') elif [ -n "${FOLDERS}" ] ; then info "Creating partial backup" From ef33989b341b78fe79d472094871951fc41ec7eb Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 00:37:56 +0000 Subject: [PATCH 27/42] keep_local_backup --- remote-backup/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index 11e1195..ee0f5d3 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -34,7 +34,7 @@ options: exclude_addons: "" remote_directory: "" zip_password: "" - keep_local_backup: "" + keep_local_backup: "all" rsync_enabled: false rsync_verbose: false rsync_host: "" From 39cb1c29e253a86e068402e95f8ffa58e7832855 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 00:42:43 +0000 Subject: [PATCH 28/42] switch to kofi --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e8512be..31d5c68 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@ # Remote Backup + This add-on is a fork of the work of [carstenschroeder] which was originally created by [overkill32] + # Installation + This add-on can be added via my [Home Assistant Add-on repository](https://github.com/ikifar2012/ha-addons): [![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fikifar2012%2Fha-addons) # [Documentation](https://addons.mathesonsteplock.ca/docs/addons/remote-backup/basic-config) -# Support Me -[![Buy me a coffee][buymeacoffee-logo]][buymeacoffee] +# Support Me + +[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/mathesonsteplock) [buymeacoffee-logo]: https://cdn.buymeacoffee.com/buttons/default-black.png [buymeacoffee]: https://www.buymeacoffee.com/mathesonstep From 33efc386c197941d8cd8f7ff98dd2144f4be69ef Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 00:51:03 +0000 Subject: [PATCH 29/42] switch to kofi --- README.md | 2 -- remote-backup/DOCS.md | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 31d5c68..76743e4 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ This add-on can be added via my [Home Assistant Add-on repository](https://githu [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/mathesonsteplock) -[buymeacoffee-logo]: https://cdn.buymeacoffee.com/buttons/default-black.png -[buymeacoffee]: https://www.buymeacoffee.com/mathesonstep [overkill32]: https://github.com/overkill32/hassio-remote-backup [carstenschroeder]: https://github.com/carstenschroeder/hassio-addons [here]: https://www.home-assistant.io/hassio/installing_third_party_addons/ diff --git a/remote-backup/DOCS.md b/remote-backup/DOCS.md index 8647af6..50cfaed 100644 --- a/remote-backup/DOCS.md +++ b/remote-backup/DOCS.md @@ -4,7 +4,4 @@ Please visit the documentation at [addons.mathesonsteplock.ca](https://addons.ma # Support Me -[![Buy me a coffee][buymeacoffee-logo]][buymeacoffee] - -[buymeacoffee-logo]: https://cdn.buymeacoffee.com/buttons/default-black.png -[buymeacoffee]: https://www.buymeacoffee.com/mathesonstep \ No newline at end of file +[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/mathesonsteplock) From 612615336c8902cd88fc18b781082a875ea1dc41 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 00:59:56 +0000 Subject: [PATCH 30/42] added changelog --- remote-backup/CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/remote-backup/CHANGELOG.md b/remote-backup/CHANGELOG.md index 42944b2..8d75009 100644 --- a/remote-backup/CHANGELOG.md +++ b/remote-backup/CHANGELOG.md @@ -1,3 +1,13 @@ +# 2022.5.0 + +- Updated base image to 11.1.2 +- Added support for `HostKeyAlgorithms` hopefully fixing #37 +- Added support for excluding addons from backup +- Added support for excluding folders from backup +- Fixed shellcheck warnings + +**Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2022.1.1...2022.5.0 + # 2022.1.1 - Updated url in `config.yaml` @@ -37,7 +47,7 @@ # 2021.10.0 - Upgraded Base to 10.1.1 -- Upgraded Home Assistant CLI to 4.14.0 +- Upgraded Home Assistant CLI to 4.14.0 - Changed from `snapshots` to `backups` (See Breaking Change #26) # 2021.9.0 From 6b494597c54e78e98d1679fed67732f53dc000a0 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 01:14:10 +0000 Subject: [PATCH 31/42] Added minimum Home Assistant version to changelog --- remote-backup/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/remote-backup/CHANGELOG.md b/remote-backup/CHANGELOG.md index 8d75009..54d9fce 100644 --- a/remote-backup/CHANGELOG.md +++ b/remote-backup/CHANGELOG.md @@ -5,6 +5,7 @@ - Added support for excluding addons from backup - Added support for excluding folders from backup - Fixed shellcheck warnings +- Added minimum Home Assistant version **Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2022.1.1...2022.5.0 From 47afe8536b931a03158a4e6009deb5cc2f87ee6d Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 01:25:28 +0000 Subject: [PATCH 32/42] Added minimum Home Assistant version as per #26 --- remote-backup/config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index ee0f5d3..0dfbe13 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -12,6 +12,7 @@ arch: - armhf - armv7 - i386 +homeassistant: "2021.9.0" hassio_api: true hassio_role: manager map: From 14858299cf3661cd14b5a1461b84ce24e7738824 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 01:26:40 +0000 Subject: [PATCH 33/42] fix match --- remote-backup/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-backup/config.yaml b/remote-backup/config.yaml index 0dfbe13..ff96ba8 100644 --- a/remote-backup/config.yaml +++ b/remote-backup/config.yaml @@ -63,7 +63,7 @@ schema: exclude_addons: str? remote_directory: str? zip_password: str? - keep_local_backup: int? + keep_local_backup: match(^(all|[+]?\d*)$) rsync_enabled: bool? rsync_verbose: bool? rsync_host: str? From c20d893356a9c8508caeadb6a9f5f8da1f9c2007 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 01:51:58 +0000 Subject: [PATCH 34/42] Update Changelog to include - Sign images with Codenotary CAS --- remote-backup/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/remote-backup/CHANGELOG.md b/remote-backup/CHANGELOG.md index 54d9fce..c621759 100644 --- a/remote-backup/CHANGELOG.md +++ b/remote-backup/CHANGELOG.md @@ -6,6 +6,7 @@ - Added support for excluding folders from backup - Fixed shellcheck warnings - Added minimum Home Assistant version +- Sign images with Codenotary CAS **Full Changelog**: https://github.com/ikifar2012/remote-backup-addon/compare/2022.1.1...2022.5.0 From 8fa4c59901ce3b7abcdd1493984786a47a80ae7f Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 01:52:12 +0000 Subject: [PATCH 35/42] Sign images with Codenotary CAS --- .github/workflows/publish.yaml | 4 +++- remote-backup/build.yaml | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 21b9a59..f29a700 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -21,9 +21,11 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Publish uses: home-assistant/builder@master + env: + - CAS_API_KEY: ${{ secrets.CAS_API_KEY }} with: args: | --all \ --target remote-backup \ --docker-user ${{ secrets.DOCKERHUB_USERNAME }} \ - --docker-password ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file + --docker-password ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/remote-backup/build.yaml b/remote-backup/build.yaml index 6598c99..688b837 100644 --- a/remote-backup/build.yaml +++ b/remote-backup/build.yaml @@ -5,3 +5,6 @@ build_from: armhf: ghcr.io/hassio-addons/base/armhf:11.1.2 armv7: ghcr.io/hassio-addons/base/armv7:11.1.2 i386: ghcr.io/hassio-addons/base/i386:11.1.2 +codenotary: true +codenotary.signer: "cas@mathesonsteplock.ca" +codenotary.base_image: "notary@home-assistant.io" From c54ee6a09147e26a00abeb042f501f24730b20f3 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 02:01:23 +0000 Subject: [PATCH 36/42] fixing cas formatting --- .github/workflows/publish.yaml | 2 +- remote-backup/build.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index f29a700..42612ea 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -21,7 +21,7 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Publish uses: home-assistant/builder@master - env: + secrets: - CAS_API_KEY: ${{ secrets.CAS_API_KEY }} with: args: | diff --git a/remote-backup/build.yaml b/remote-backup/build.yaml index 688b837..9c73589 100644 --- a/remote-backup/build.yaml +++ b/remote-backup/build.yaml @@ -5,6 +5,6 @@ build_from: armhf: ghcr.io/hassio-addons/base/armhf:11.1.2 armv7: ghcr.io/hassio-addons/base/armv7:11.1.2 i386: ghcr.io/hassio-addons/base/i386:11.1.2 -codenotary: true -codenotary.signer: "cas@mathesonsteplock.ca" -codenotary.base_image: "notary@home-assistant.io" +codenotary: + signer: "cas@mathesonsteplock.ca" + base_image: "notary@home-assistant.io" From 43f862c14fb5e07f212ad9064e4bc4991840ce62 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 02:31:09 +0000 Subject: [PATCH 37/42] fix signature --- remote-backup/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remote-backup/build.yaml b/remote-backup/build.yaml index 9c73589..feaadcb 100644 --- a/remote-backup/build.yaml +++ b/remote-backup/build.yaml @@ -6,5 +6,5 @@ build_from: armv7: ghcr.io/hassio-addons/base/armv7:11.1.2 i386: ghcr.io/hassio-addons/base/i386:11.1.2 codenotary: - signer: "cas@mathesonsteplock.ca" - base_image: "notary@home-assistant.io" + signer: cas@mathesonsteplock.ca + base_image: codenotary@frenck.dev From ffd72f3c5504a9306fb7be1d82af5b3ce3f111c5 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 02:50:14 +0000 Subject: [PATCH 38/42] Add Updated HA CLI to 4.17.0 --- remote-backup/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/remote-backup/CHANGELOG.md b/remote-backup/CHANGELOG.md index c621759..fc68ddd 100644 --- a/remote-backup/CHANGELOG.md +++ b/remote-backup/CHANGELOG.md @@ -1,6 +1,7 @@ # 2022.5.0 - Updated base image to 11.1.2 +- Updated HA CLI to 4.17.0 - Added support for `HostKeyAlgorithms` hopefully fixing #37 - Added support for excluding addons from backup - Added support for excluding folders from backup From b18f305300a02fd5d43822c9487c189e60ca7977 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 04:02:16 +0000 Subject: [PATCH 39/42] debugging --- remote-backup/run.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index fe5cfdd..6314439 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -67,18 +67,20 @@ function create-local-backup { FOLDERS="" ADDONS="" BASE_FOLDERS="addons/local homeassistant media share ssl" - INSTALLED_ADDONS=$(bashio::addons.installed) + UNFORMATTED_INSTALLED_ADDONS=$(bashio::addons.installed) + INSTALLED_ADDONS=$(echo "${UNFORMATTED_INSTALLED_ADDONS}" | tr '\n' ' ') name="${CUSTOM_PREFIX} $(date +'%Y-%m-%d %H-%M')" warn "Creating local backup: \"${name}\"" if [ -n "${EXCLUDE_ADDONS}" ] || [ -n "${EXCLUDE_FOLDERS}" ] ; then info "Creating partial backup" + set -x for addon in ${INSTALLED_ADDONS} ; do - for excluded_addon in ${EXCLUDE_ADDONS} ; do - if [ "${addon}" = "${excluded_addon}" ] ; then - warn "Excluding addon: ${addon}" - else - ADDONS="${ADDONS}--addons=${addon} " - fi + for excluded_addon in ${EXCLUDE_ADDONS} ; do + if [ "${addon}" = "${excluded_addon}" ] ; then + warn "Excluding addon: ${addon}" + else + ADDONS="${ADDONS}--addons=${addon} " + fi done done for folder in ${BASE_FOLDERS} ; do From 5d3828b11ad1eca7f03e91aec5d3fc7519352323 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 May 2022 04:10:08 +0000 Subject: [PATCH 40/42] change var name --- remote-backup/run.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 6314439..c148fba 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -74,15 +74,18 @@ function create-local-backup { if [ -n "${EXCLUDE_ADDONS}" ] || [ -n "${EXCLUDE_FOLDERS}" ] ; then info "Creating partial backup" set -x - for addon in ${INSTALLED_ADDONS} ; do - for excluded_addon in ${EXCLUDE_ADDONS} ; do - if [ "${addon}" = "${excluded_addon}" ] ; then - warn "Excluding addon: ${addon}" + for ha_addon in ${INSTALLED_ADDONS} + do + for excluded_addon in ${EXCLUDE_ADDONS} + do + if [ "${ha_addon}" = "${excluded_addon}" ] ; then + warn "Excluding addon: ${ha_addon}" else - ADDONS="${ADDONS}--addons=${addon} " + ADDONS="${ADDONS}--addons=${ha_addon} " fi + done done - done + for folder in ${BASE_FOLDERS} ; do for excluded_folder in ${EXCLUDE_FOLDERS} ; do if [ "${folder}" = "${excluded_folder}" ] ; then From d8824f78df03ae2578fd2cc9dc5bdd873c7703cf Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Thu, 12 May 2022 21:31:56 -0400 Subject: [PATCH 41/42] fixes --- remote-backup/run.sh | 54 ++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index c148fba..8a233f1 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -67,49 +67,39 @@ function create-local-backup { FOLDERS="" ADDONS="" BASE_FOLDERS="addons/local homeassistant media share ssl" - UNFORMATTED_INSTALLED_ADDONS=$(bashio::addons.installed) - INSTALLED_ADDONS=$(echo "${UNFORMATTED_INSTALLED_ADDONS}" | tr '\n' ' ') + INSTALLED_ADDONS=$(bashio::addons.installed) name="${CUSTOM_PREFIX} $(date +'%Y-%m-%d %H-%M')" warn "Creating local backup: \"${name}\"" if [ -n "${EXCLUDE_ADDONS}" ] || [ -n "${EXCLUDE_FOLDERS}" ] ; then - info "Creating partial backup" - set -x - for ha_addon in ${INSTALLED_ADDONS} - do - for excluded_addon in ${EXCLUDE_ADDONS} - do - if [ "${ha_addon}" = "${excluded_addon}" ] ; then - warn "Excluding addon: ${ha_addon}" - else - ADDONS="${ADDONS}--addons=${ha_addon} " - fi - done - done - - for folder in ${BASE_FOLDERS} ; do - for excluded_folder in ${EXCLUDE_FOLDERS} ; do - if [ "${folder}" = "${excluded_folder}" ] ; then - warn "Excluding folder: ${folder}" - else - FOLDERS="${FOLDERS}--folders=${folder} " - fi + EXCLUDED_FOLDERS=$(echo "${EXCLUDE_FOLDERS}" | tr ',' '\n') + EXCLUDED_ADDONS=$(echo "${EXCLUDE_ADDONS}" | tr ',' '\n') + echo "Excluded folders: ${EXCLUDED_FOLDERS}" + echo "Excluded addons: ${EXCLUDED_ADDONS}" + UNFORMATTED_FOLDERS="${BASE_FOLDERS}" + UNFORMATTED_ADDONS="${INSTALLED_ADDONS}" + if [ -n "${EXCLUDED_FOLDERS}" ] ; then + for folder in ${EXCLUDED_FOLDERS} ; do + UNFORMATTED_FOLDERS=$(echo "${UNFORMATTED_FOLDERS}" | sed -e "s/${folder}//g") done + fi + if [ -n "${EXCLUDED_ADDONS}" ] ; then + for addon in ${EXCLUDED_ADDONS} ; do + UNFORMATTED_ADDONS="$(echo "${UNFORMATTED_ADDONS}" | sed -e "s/${addon}//g")" done fi - if [ -n "${FOLDERS}" ] && [ -n "${ADDONS}" ] ; then + if [ -n "${UNFORMATTED_ADDONS}" ] && [ -n "${UNFORMATTED_FOLDERS}" ] ; then + for addon in ${UNFORMATTED_ADDONS} ; do + ADDONS="${ADDONS}--addons ${addon} " + done + for folder in ${UNFORMATTED_FOLDERS} ; do + FOLDERS="${FOLDERS}--folders ${folder} " + done + fi info "Creating partial backup" if [ "${DEBUG}" = true ] ; then warn "Including ${FOLDERS} and ${ADDONS}" fi slug=$(ha backups new --raw-json --name="${name}" ${ADDONS} ${FOLDERS} | jq --raw-output '.data.slug') - elif [ -n "${FOLDERS}" ] ; then - info "Creating partial backup" - info "Including ${FOLDERS}" - slug=$(ha backups new --raw-json --name="${name}" ${FOLDERS} | jq --raw-output '.data.slug') - elif [ -n "${ADDONS}" ] ; then - info "Creating partial backup" - info "Including ${ADDONS}" - slug=$(ha backups new --raw-json --name="${name}" ${ADDONS} | jq --raw-output '.data.slug') else info "Creating full backup" slug=$(ha backups new --raw-json --name="${name}" | jq --raw-output '.data.slug') From 5f89bd04b22e53c7324d9de3f7853b20620d4789 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Thu, 12 May 2022 22:23:46 -0400 Subject: [PATCH 42/42] cleanup debug messages --- remote-backup/run.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/remote-backup/run.sh b/remote-backup/run.sh index 8a233f1..9a4ad56 100644 --- a/remote-backup/run.sh +++ b/remote-backup/run.sh @@ -73,8 +73,10 @@ function create-local-backup { if [ -n "${EXCLUDE_ADDONS}" ] || [ -n "${EXCLUDE_FOLDERS}" ] ; then EXCLUDED_FOLDERS=$(echo "${EXCLUDE_FOLDERS}" | tr ',' '\n') EXCLUDED_ADDONS=$(echo "${EXCLUDE_ADDONS}" | tr ',' '\n') - echo "Excluded folders: ${EXCLUDED_FOLDERS}" - echo "Excluded addons: ${EXCLUDED_ADDONS}" + if [ "$DEBUG" = true ] ; then + warn "\n Excluded folders: \n ${EXCLUDED_FOLDERS}\n---------------" + warn "\n Excluded addons: \n ${EXCLUDED_ADDONS}\n----------------" + fi UNFORMATTED_FOLDERS="${BASE_FOLDERS}" UNFORMATTED_ADDONS="${INSTALLED_ADDONS}" if [ -n "${EXCLUDED_FOLDERS}" ] ; then