Skip to content

Commit

Permalink
Update run.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
TheStigh authored Feb 3, 2020
1 parent 5de764f commit 9b0138e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions remote-backup/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ function add-ssh-key {
function copy-backup-to-remote {

cd /backup/
if [[ -z $ZIP_PASSWORD ]]; then
echo "Copying ${slug}.tar to ${REMOTE_DIRECTORY} on ${SSH_HOST} using SCP"
scp -F "${HOME}/.ssh/config" "${slug}.tar" remote:"${REMOTE_DIRECTORY}"
else
echo "Copying password-protected ${slug}.zip to ${REMOTE_DIRECTORY} on ${SSH_HOST} using SCP"
zip -P "$ZIP_PASSWORD" "${slug}.zip" "${slug}".tar
scp -F "${HOME}/.ssh/config" "${slug}.zip" remote:"${REMOTE_DIRECTORY}" && rm "${slug}.zip"
fi

echo "Copying ${slug}.tar to ${REMOTE_DIRECTORY} on ${SSH_HOST} using SCP"
scp -F "${HOME}/.ssh/config" "${slug}.tar" remote:"${REMOTE_DIRECTORY}"
}

function delete-local-backup {
Expand All @@ -57,7 +50,7 @@ function delete-local-backup {
:
elif [[ -z ${KEEP_LOCAL_BACKUP} ]]; then
echo "Deleting local backup: ${slug}"
hassio snapshots remove -name "${slug}"
hassio snapshots remove --name "${slug}"
else

last_date_to_keep=$(hassio snapshots list | jq .data.snapshots[].date | sort -r | \
Expand All @@ -66,7 +59,7 @@ function delete-local-backup {
hassio snapshots list | jq -c .data.snapshots[] | while read backup; do
if [[ $(echo ${backup} | jq .date | xargs date -D "%Y-%m-%dT%T" +%s --date ) -lt ${last_date_to_keep} ]]; then
echo "Deleting local backup: $(echo ${backup} | jq -r .slug)"
hassio snapshots remove -name "$(echo ${backup} | jq -r .slug)"
hassio snapshots remove --name "$(echo ${backup} | jq -r .slug)"
fi
done

Expand All @@ -76,7 +69,11 @@ function delete-local-backup {
function create-local-backup {
name="Automated backup $(date +'%Y-%m-%d %H:%M')"
echo "Creating local backup: \"${name}\""
slug=$(hassio snapshots new --name="${name}" | cut -d' ' -f2)
if [[ -z $ZIP_PASSWORD ]]; then
slug=$(hassio snapshots new --name="${name}" | jq --raw-output '.data.slug')
else
slug=$(hassio snapshots new --name="${name}" --password="${ZIP_PASSWORD}" | jq --raw-output '.data.slug')
fi
echo "Backup created: ${slug}"
}

Expand Down

0 comments on commit 9b0138e

Please sign in to comment.