• Uncategorized

About linux : Delete-Recreate-All-Kafka-Topics-in-Bash-Terminal

Question Detail

Using the Bash shell, is there a way to delete and then recreate all the Kafka topics shown from running the command

kafka-topics --zookeeper localhost:2181

Question Answer

There isn’t, since that command alone doesn’t include topic settings or partition count.

You’d need to take the output of that script, loop it over all results, pass to kafka-topics --describe, then parse that output, and finally build a command to kafka-topics --delete and --create.
Keep in mind that the --zookeeper option is deprecated.

Another option would be to use zookeeper-shell to backup and iterate the /topics Znode information, but I think this will be missing topic configurations.

If the goal is to easily restore topic information, one suggestion would be to centrally manage how topics actually get created, such as via Terraform or Kubernetes Kafka Operators along with proper GitOps/DevOps processes. This would also be a good way to discover and create topic access-controls or schemas.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.