Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created January 20, 2022 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimbatm/b235775c6191abfee075ac4c4fd3d9af to your computer and use it in GitHub Desktop.
Save zimbatm/b235775c6191abfee075ac4c4fd3d9af to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Dump all the schemas from the registry $scr to $dir
set -euo pipefail
scr=${1:-localhost:8081}
dir=${2:-$PWD}
curl -s "${scr}/subjects" | jq -r .[] | while read -r subject; do
curl -s "${scr}/subjects/${subject}/versions" | jq -r .[] | while read -r version; do
# get the schema for a subject and version to a file
data=$(curl -s "${scr}/subjects/${subject}/versions/${version}")
id=$(echo "${data}" | jq .id)
file=${id}_${version}_${subject}
echo "${file}"
echo "$data" > "${dir}/${file}"
done
done
#!/usr/bin/env bash
# shellcheck disable=SC2012 disable=SC2002
#
# Restore the schemas in $dir to the $scr registry. The format in $dir follows
# the sc-dump.sh format.
set -euo pipefail
scr=${1:-localhost:8081}
dir=${2:-$PWD}
for file in $(ls -1 "$dir"/*_*_* | sort -n); do
echo "file=$file"
subject=$(echo "${file}" | cut -d_ -f3-)
old_id=$(jq -r .id "$file")
# schema reg API doesn't expect those in the JSON - so we remove
data=$(cat "${file}" | jq -c 'del(.subject) | del(.version) | del(.id)')
ret=$(curl -v "${scr}/subjects/${subject}/versions" -H "Content-Type: application/vnd.schemaregistry.v1+json" --data "$data")
echo "$ret"
new_id=$(echo "$ret" | jq -r .id)
if [[ $new_id != "$old_id" ]]; then
echo "oops, ID mismatch! new_id=$new_id old_id=$old_id file=$file" >&2
exit 1
fi
# scrolling too fast
# sleep 0.5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment