diff --git a/roles/log-detective-backup/templates/backup.sh.j2 b/roles/log-detective-backup/templates/backup.sh.j2 index d023ee3f5d..0f1e04b64e 100644 --- a/roles/log-detective-backup/templates/backup.sh.j2 +++ b/roles/log-detective-backup/templates/backup.sh.j2 @@ -1,5 +1,22 @@ -#! /bin/sh +#!/bin/bash + +set -e basename=$(date +%s).tar.gz +ld_backup_path="{{ ld_backup_path }}" +backup_path=$ld_backup_path/$basename -wget -O "{{ ld_backup_path }}/$basename" "{{ ld_dump_url }}" +# Find last modified +recent=$(find "$ld_backup_path" -type f -name "*tar.gz" -mtime -1 | sort | tail -n 1) + +wget -O "$backup_path" "{{ ld_dump_url }}" + +# Extract both and get hashes +new=$(tar -xzf "$backup_path" -O | sha256sum) +old=$(tar -xzf "$recent" -O | sha256sum) + +# Compare hashes +if [ "$new" = "$old" ]; then + echo No changes since last backup, removing downloaded archive + rm "$recent" +fi