Last active
October 23, 2020 14:01
-
-
Save JensRantil/810caee0e0ad62ab69ee74ec520b8e56 to your computer and use it in GitHub Desktop.
Kafka script to generate Bash commands that will recreate Kafka topics. Possibly useful for backups of topics.
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
./bin/kafka-topics.sh --if-not-exists --zookeeper $(grep -E zookeeper.connect= ./config/server.properties | cut -d= -f2) --create --partitions 12 --replication-factor 3 --topic my-topic-1 --config retention.ms=3600000 --config min.insync.replicas=2 | |
./bin/kafka-topics.sh --if-not-exists --zookeeper $(grep -E zookeeper.connect= ./config/server.properties | cut -d= -f2) --create --partitions 1 --replication-factor 3 --topic my-topic-2 --config min.insync.replicas=2 |
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
#!/bin/bash | |
./bin/kafka-topics.sh --zookeeper $(grep -E "zookeeper.connect=" ./config/server.properties | cut -d= -f2) --describe \ | |
| grep PartitionCount \ | |
| awk -F '\t' 'BEGIN {OFS=":";} {print $1, $2, $3, $4}' \ | |
| sed 's/,/:/g' \ | |
| awk -F: '{printf "./bin/kafka-topics.sh --if-not-exists --zookeeper $(grep -E zookeeper.connect= ./config/server.properties | cut -d= -f2) --create --partitions %d --replication-factor %d --topic %s", $4, $6, $2;for(i=8; i<=NF; i++) {printf " --config %s", $i;};printf "\n";}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs more
awk
!