Skip to content

Commit

Permalink
Update script for Watson Discovery 4.8.5 on CP4D
Browse files Browse the repository at this point in the history
  • Loading branch information
KosukeOkamoto committed Apr 24, 2024
1 parent 286743f commit 00c7db1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions discovery-data/latest/all-backup-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SPLIT_DIR=./tmp_split_backup
EXTRA_OC_ARGS="${EXTRA_OC_ARGS:-}"

SCRIPT_DIR=$(dirname $0)
KUBECONFIG_FILE="${SCRIPT_DIR}/.kubeconfig"

. ${SCRIPT_DIR}/lib/function.bash

Expand Down Expand Up @@ -504,6 +505,8 @@ fi
brlog "INFO" "Clean up"

delete_service_account "${BACKUP_RESTORE_SA}"
rm -f "${KUBECONFIG_FILE}"
unset KUBECONFIG
rm -rf "${BACKUP_DIR}"

disable_trap
Expand Down
10 changes: 8 additions & 2 deletions discovery-data/latest/elastic-backup-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ printUsage() {
exit 1
}

get_recovery_status(){
fetch_cmd_result ${ELASTIC_POD} 'rm -f /tmp/recovery_status.json && export ELASTIC_ENDPOINT=https://localhost:9200 && curl -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_recovery" > /tmp/recovery_status.json && cat /tmp/recovery_status.json' ${OC_ARGS} -c elasticsearch
}

if [ $# -lt 2 ] ; then
printUsage
fi
Expand Down Expand Up @@ -417,7 +421,7 @@ EOF
total_shards=0
while true;
do
recovery_status=$(fetch_cmd_result ${ELASTIC_POD} 'rm -f /tmp/recovery_status.json && export ELASTIC_ENDPOINT=https://localhost:9200 && curl -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_recovery" > /tmp/recovery_status.json && cat /tmp/recovery_status.json' ${OC_ARGS} -c elasticsearch)
recovery_status=$(get_recovery_status)
brlog "DEBUG" "Recovery Status: ${recovery_status}"
if [ "${recovery_status}" != "{}" ] ; then
tmp_total_shards=$(fetch_cmd_result ${ELASTIC_POD} 'cat /tmp/recovery_status.json | jq ".[].shards[]" | jq -s ". | length"' ${OC_ARGS} -c elasticsearch)
Expand All @@ -441,7 +445,9 @@ EOF
brlog "INFO" "Total shards in snapshot: ${total_shards}"
while true;
do
done_count=$(fetch_cmd_result ${ELASTIC_POD} 'export ELASTIC_ENDPOINT=https://localhost:9200 && curl -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_recovery" | jq '"'"'.[].shards[] | select(.stage == "DONE")'"'"' | jq -s ". | length"' ${OC_ARGS} -c elasticsearch)
recovery_status=$(get_recovery_status)
total_shards=$(fetch_cmd_result ${ELASTIC_POD} 'cat /tmp/recovery_status.json | jq ".[].shards[]" | jq -s ". | length"' ${OC_ARGS} -c elasticsearch)
done_count=$(fetch_cmd_result ${ELASTIC_POD} 'cat /tmp/recovery_status.json | jq '"'"'.[].shards[] | select(.stage == "DONE")'"'"' | jq -s ". | length"' ${OC_ARGS} -c elasticsearch)
brlog "INFO" "${done_count} shards finished"
if [ ${done_count} -ge ${total_shards} ] ; then
break
Expand Down
6 changes: 4 additions & 2 deletions discovery-data/latest/lib/function.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,10 @@ delete_service_account(){
oc_login_as_scripts_user(){
create_service_account "${BACKUP_RESTORE_SA}"
local oc_token=$(get_oc_token "${BACKUP_RESTORE_SA}")
local cluster=$(oc config view --minify --output jsonpath='{..server}')
oc login "${cluster}" --token="${oc_token}"
local cluster=$(oc config view --minify -o jsonpath='{..server}')
local namespace=$(oc config view --minify -o jsonpath='{..namespace}')
export KUBECONFIG="${KUBECONFIG_FILE:-${PWD}/.kubeconfig}"
oc login "${cluster}" --token="${oc_token}" -n "${namespace}" --insecure-skip-tls-verify
trap_add "brlog 'INFO' 'You currently oc login as a scripts ServiceAccount. You can rerun scripts with this. Please delete ServiceAccount ${BACKUP_RESTORE_SA} and clusterrolebinding ${BACKUP_RESTORE_SA}-cluster-rb when you complete backup or restore'"

}
Expand Down
2 changes: 1 addition & 1 deletion discovery-data/latest/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
The Backup and Restore Scripts for the Watson Discovery on CP4D.
Scripts Version: 4.8.4
Scripts Version: 4.8.5

0 comments on commit 00c7db1

Please sign in to comment.