Bug fixing on restore

This commit is contained in:
John 2025-04-27 20:53:26 +12:00
parent acb462d15e
commit 5bc7a05a46
2 changed files with 11 additions and 2 deletions

View File

@ -145,3 +145,11 @@ check_required_env_vars() {
fi
done
}
function _root_remove_tree() {
local to_remove="$1"
parent=$(dirname "$to_remove")
abs_parent=$(realpath "$parent")
child=$(basename "$to_remove")
docker run --rm -v "$abs_parent":/data alpine rm -rf "/data/$child"
}

View File

@ -24,13 +24,14 @@ bash ./uninstall.sh || die "Failed to uninstall service before restore"
# Remove existing data folder
echo "Deleting ALL data in $LOCAL_DATA_FOLDER."
rm -rf "$LOCAL_DATA_FOLDER"
_root_remove_tree "$LOCAL_DATA_FOLDER"
[ ! -d "$LOCAL_DATA_FOLDER" ] || die "Failed to delete $LOCAL_DATA_FOLDER"
mkdir -p "$LOCAL_DATA_FOLDER"
[ -d "$LOCAL_DATA_FOLDER" ] || die "Failed to create $LOCAL_DATA_FOLDER"
# Restore data folder from backup
if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER"; then
# --strip-components=1 removes the parent folder in the tgz from the restore paths.
if ! tar xzvf --strip-components=1 "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER"; then
die "Failed to restore data folder from backup"
fi