Last active
January 18, 2024 16:26
-
-
Save ram-pi/91031191d854d43d8125a9518087638e to your computer and use it in GitHub Desktop.
Confluent Cloud - Failover all mirror topics
This file contains hidden or 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 | |
# This script is used to failover all the mirror topics from one link to another | |
# Usage: ./run.sh <link_id> | |
# Example: ./run.sh link2 | |
# prerequisites: | |
# - install jq | |
# - install confluent cli | |
# - login to confluent cloud using "confluent login" and select the environment and cluster with "confluent env use xxx" and "confluent kafka cluster use xxx | |
# check if link_id is empty | |
if [ -z "$1" ] | |
then | |
echo "No link_id argument supplied" | |
fi | |
# print help if no argument is passed | |
if [ $# -eq 0 ] | |
then | |
echo "Usage: ./run.sh <link_id>" | |
echo "Example: ./run.sh link2" | |
exit 1 | |
fi | |
# get link_id from args | |
link_id=$1 | |
# get command output in a variable | |
output=$(confluent kafka mirror list --link $link_id --output json | jq '.[].mirror_topic_name') | |
# remove double quotes from the output | |
output=${output//\"/} | |
#echo "RUNNING: confluent kafka mirror failover $output --link $link_id --dry-run" | |
# run the command with --dry-run option | |
confluent kafka mirror failover $output --link $link_id --dry-run | |
# ask the user to confirm - type "Y"" to confirm | |
read -p "Do you want to continue? (Y/N) " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
confluent kafka mirror failover $output --link $link_id | |
confluent kafka mirror list --link $link_id | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment