Last active
November 15, 2023 13:48
-
-
Save kppullin/81c0e7a5e8c334271825679e79ee82d1 to your computer and use it in GitHub Desktop.
Simple script to dump all kafka topics to json files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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