Skip to content

Instantly share code, notes, and snippets.

@kppullin
Last active November 15, 2023 13:48
Show Gist options
  • Save kppullin/81c0e7a5e8c334271825679e79ee82d1 to your computer and use it in GitHub Desktop.
Save kppullin/81c0e7a5e8c334271825679e79ee82d1 to your computer and use it in GitHub Desktop.
Simple script to dump all kafka topics to json files
#!/usr/bin/env bash
# Overview:
# 1) Get list of all topic names
# 2) Iterate list, dumping each one to json
# Pre-reqs:
# 1) kafkacat
# 2) jq
mkdir ./output
broker="<BROKER>"
topics=$(kafkacat -b ${broker} -L -J | jq -r '.topics[].topic' | sort)
for topic in $topics; do
# Ignore "private"/"internal" topics. Adjust as needed.
if [[ $topic == "_"* ]]; then
continue
fi
echo "Dumping $topic"
kafkacat -b ${broker} -C -J -e -q -o beginning -t "${topic}" > "./output/$topic.json"
done
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment