Skip to content

Commit

Permalink
Merge pull request #27 from ikifar2012/2021.10.0
Browse files Browse the repository at this point in the history
- Upgraded Base to 10.1.1
- Upgraded Home Assistant CLI to 4.14.0 
- Changed from `snapshots` to `backups` (See Breaking Change #26)
  • Loading branch information
ikifar2012 authored Oct 10, 2021
2 parents ceb59fa + 4ee2b7c commit 43f435e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
6 changes: 6 additions & 0 deletions remote-backup/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 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
Expand Down
2 changes: 1 addition & 1 deletion remote-backup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.12.3/ha_${BUILD_ARCH}" \
RUN wget -O /usr/bin/ha "https://github.com/home-assistant/cli/releases/download/4.14.0/ha_${BUILD_ARCH}" \
&& chmod a+x /usr/bin/ha

# Copy data
Expand Down
10 changes: 5 additions & 5 deletions remote-backup/build.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"squash": false,
"build_from": {
"aarch64": "ghcr.io/hassio-addons/base/aarch64:10.0.2",
"amd64": "ghcr.io/hassio-addons/base/amd64:10.0.2",
"armhf": "ghcr.io/hassio-addons/base/armhf:10.0.2",
"armv7": "ghcr.io/hassio-addons/base/armv7:10.0.2",
"i386": "ghcr.io/hassio-addons/base/i386:10.0.2"
"aarch64": "ghcr.io/hassio-addons/base/aarch64:10.1.1",
"amd64": "ghcr.io/hassio-addons/base/amd64:10.1.1",
"armhf": "ghcr.io/hassio-addons/base/armhf:10.1.1",
"armv7": "ghcr.io/hassio-addons/base/armv7:10.1.1",
"i386": "ghcr.io/hassio-addons/base/i386:10.1.1"
},
"args": {}
}
4 changes: 2 additions & 2 deletions remote-backup/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "Remote Backup",
"version": "2021.9.0",
"version": "2021.10.0",
"slug": "remote_backup",
"description": "Automatically create and backup HA snapshots using SCP",
"description": "Automatically create and backup HA backups using SCP",
"url": "https://github.com/ikifar2012/remote-backup-addon/blob/master/README.md",
"startup": "once",
"image": "ikifar/remote-backup-{arch}",
Expand Down
16 changes: 8 additions & 8 deletions remote-backup/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function add-ssh-key {
function create-local-backup {
name="${CUSTOM_PREFIX} $(date +'%Y-%m-%d %H-%M')"
echo "Creating local backup: \"${name}\""
slug=$(ha snapshots new --raw-json --name="${name}" | jq --raw-output '.data.slug')
slug=$(ha backups new --raw-json --name="${name}" | jq --raw-output '.data.slug')
echo "Backup created: ${slug}"
}

Expand Down Expand Up @@ -104,7 +104,7 @@ function rsync_folders {
fi
}

function rclone_snapshots {
function rclone_backups {
if [ "$RCLONE_ENABLED" = true ] ; then
cd /backup/
mkdir -p ~/.config/rclone/
Expand Down Expand Up @@ -146,22 +146,22 @@ function rclone_snapshots {

function delete-local-backup {

ha snapshots reload
ha backups reload

if [[ ${KEEP_LOCAL_BACKUP} == "all" ]]; then
:
elif [[ -z ${KEEP_LOCAL_BACKUP} ]]; then
echo "Deleting local backup: ${slug}"
ha snapshots remove "${slug}"
ha backups remove "${slug}"
else

last_date_to_keep=$(ha snapshots list --raw-json | jq .data.snapshots[].date | sort -r | \
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 snapshots list --raw-json | jq -c .data.snapshots[] | while read backup; do
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
echo "Deleting local backup: $(echo ${backup} | jq -r .slug)"
ha snapshots remove "$(echo ${backup} | jq -r .slug)"
ha backups remove "$(echo ${backup} | jq -r .slug)"
fi
done

Expand All @@ -172,7 +172,7 @@ add-ssh-key
create-local-backup
copy-backup-to-remote
rsync_folders
rclone_snapshots
rclone_backups
delete-local-backup

echo "Backup process done!"
Expand Down

0 comments on commit 43f435e

Please sign in to comment.