diff --git a/templates/example-nginx/_common.sh b/templates/example-nginx/_common.sh index ec4aca2..8c9d4e1 100755 --- a/templates/example-nginx/_common.sh +++ b/templates/example-nginx/_common.sh @@ -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" +} diff --git a/templates/example-nginx/restore.sh b/templates/example-nginx/restore.sh index 3377119..6760659 100644 --- a/templates/example-nginx/restore.sh +++ b/templates/example-nginx/restore.sh @@ -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