Newly downloaded archive is compared against existing files to ensure uniqueness

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
This commit is contained in:
Jiri Podivin 2024-10-31 13:48:54 +01:00 committed by praiskup
parent 9bc7448cb3
commit 1a3efadea2

View file

@ -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