Skip to content

Commit 9185681

Browse files
authored
fix: kafka backup using sasl (#2283)
1 parent 994933e commit 9185681

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

addons/kafka/dataprotection/backup.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
#!/bin/bash
22

3+
# if the script exits with a non-zero exit code, touch a file to indicate that the backup failed,
4+
# the sync progress container will check this file and exit if it exists
5+
function handle_exit() {
6+
exit_code=$?
7+
if [ $exit_code -ne 0 ]; then
8+
echo "failed with exit code $exit_code"
9+
touch "${DP_BACKUP_INFO_FILE}.exit"
10+
exit $exit_code
11+
fi
12+
}
13+
14+
trap handle_exit EXIT
15+
316
# topics.txt format is like:
417
# (topic name) (partitions) (replication factor)
518
# topic1 1 1
619
# topic2 1 1
720
#
821
# We also ignores the __consumer_offsets topic as offsets won't be backuped up.
922
echo "getting topics..."
10-
kafkactl get topics | tail -n +2 | grep -v __consumer_offsets | datasafed push - topics.txt
23+
topic_list=$(kafkactl get topics | tail -n +2)
24+
if [[ -z $topic_list ]]; then
25+
echo "nothing to backup"
26+
exit 1
27+
fi
28+
echo $topic_list | grep -v __consumer_offsets | datasafed push - topics.txt
1129
readarray -t topics < <(kafkactl get topics -o compact | grep -v __consumer_offsets)
1230

1331
for topic in "${topics[@]}"; do

addons/kafka/dataprotection/common.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ function DP_save_backup_status_info() {
2626
export BROKERS="$DP_DB_HOST:$DP_DB_PORT"
2727
export PATH="$PATH:$DP_DATASAFED_BIN_PATH"
2828
export DATASAFED_BACKEND_BASE_PATH=${DP_BACKUP_BASE_PATH}
29+
30+
if [[ $KB_KAFKA_SASL_ENABLE == "true" ]]; then
31+
echo "using sasl auth.."
32+
if [[ $KB_KAFKA_SASL_MECHANISMS != *"PLAIN"* ]]; then
33+
echo "unsupported KB_KAFKA_SASL_MECHANISMS: $KB_KAFKA_SASL_MECHANISMS"
34+
exit 1
35+
fi
36+
export SASL_ENABLED="true"
37+
export SASL_MECHANISM="plaintext"
38+
export SASL_USERNAME=$KAFKA_ADMIN_USER
39+
export SASL_PASSWORD=$KAFKA_ADMIN_PASSWORD
40+
fi

0 commit comments

Comments
 (0)