Skip to content

Commit e6d0812

Browse files
authored
Merge pull request #264 from KosukeOkamoto/update-discovery-scripts-for-5.0.0
Update script for Watson Discovery 5.0.0 on CP4D
2 parents 4054970 + d6bd779 commit e6d0812

File tree

5 files changed

+180
-15
lines changed

5 files changed

+180
-15
lines changed

discovery-data/latest/all-backup-restore.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Basically, you don't need these advanced options.
4242
--datastore-archive-option="<tar_option>" Tar options for compression used on archiving the backup files of ElasticSearch, MinIO and internal configuration. Default "-z".
4343
--postgresql-archive-option="<tar_option>" Tar options for compression used on archiving the backup files of postgres. Note that the backup files of postgresql are archived on its pod by default. Default "-z".
4444
--etcd-archive-option="<tar_option>" Tar options used on archiving the backup files of etcd. Note that the backup files of etcd are archived on its pod by default. Default "-z".
45+
--reindex-old-index Reindex elastic search indices from version 6 to 7 before making the backup. If existing elastic search indices version is already 7, this flag does nothing. They have to be reindexed if you want to restore to 4.8.x. Reindex actually won't change your data, but it takes time. If you want to make the backup without reindex, use '--ignore-old-index' instead.
46+
--ignore-old-index Whether to skip reindexing old (version 6) elastic search indices before making the backup. You can proceed backup without reindex, but you can't restore the backup data to 4.8.x.
4547
--skip-verify-archive Skip the all verifying process of the archive.
4648
--skip-verify-backup Skip verifying the backup file.
4749
--skip-verify-datastore-archive Skip verifying the archive of datastores.
@@ -224,6 +226,12 @@ do
224226
--skip-quiesce)
225227
export SKIP_QUIESCE=true
226228
;;
229+
--reindex-old-index)
230+
export REINDEX_OLD_INDEX=true
231+
;;
232+
--ignore-old-index)
233+
export IGNORE_OLD_INDEX=true
234+
;;
227235
--skip-quiesce=*)
228236
export SKIP_QUIESCE="${1#--skip-quiesce=}"
229237
;;
@@ -300,6 +308,8 @@ export TENANT_NAME=${TENANT_NAME}
300308
export SCRIPT_DIR=${SCRIPT_DIR}
301309
export OC_ARGS="${EXTRA_OC_ARGS}"
302310
export CLEAN=${CLEAN:-false}
311+
export REINDEX_OLD_INDEX=${REINDEX_OLD_INDEX:-false}
312+
export IGNORE_OLD_INDEX=${IGNORE_OLD_INDEX:-false}
303313

304314
###############
305315
# Function
@@ -354,6 +364,7 @@ mkdir -p ${TMP_WORK_DIR}
354364

355365
mkdir -p "${BACKUP_RESTORE_LOG_DIR}"
356366
brlog "INFO" "Component log directory: ${BACKUP_RESTORE_LOG_DIR}"
367+
357368
CURRENT_COMPONENT="pre-process"
358369
check_datastore_available
359370
create_elastic_shared_pvc
@@ -369,8 +380,9 @@ if ! "${BACKUP_RESTORE_IN_POD:-false}" ; then
369380
export MC_COMMAND=${MC_COMMAND}
370381
fi
371382

372-
373383
if [ ${COMMAND} = 'backup' ] ; then
384+
ELASTIC_VERSION=$(get_elastic_version)
385+
validate_elastic_version "$ELASTIC_VERSION"
374386
if [ $(compare_version "${WD_VERSION}" "4.0.6") -ge 0 ] ; then
375387
create_backup_instance_mappings
376388
fi
@@ -379,11 +391,15 @@ if [ ${COMMAND} = 'backup' ] ; then
379391
quiesce
380392
fi
381393
fi
394+
if [[ ${ELASTIC_VERSION} = "ES6" ]] && [[ ${REINDEX_OLD_INDEX} = "true" ]]; then
395+
reindex_elastic_es6
396+
fi
382397
if [ $(compare_version "${WD_VERSION}" "2.1.3") -ge 0 ] ; then
383398
ALL_COMPONENT=("wddata" "etcd" "postgresql" "elastic" "minio")
384399
else
385400
ALL_COMPONENT=("wddata" "etcd" "hdp" "postgresql" "elastic")
386401
fi
402+
387403
export ALL_COMPONENT
388404
export VERIFY_COMPONENT=( "${ALL_COMPONENT[@]}")
389405
BACKUP_FILE=${BACKUP_FILE:-"watson-discovery_$(date "+%Y%m%d_%H%M%S").backup"}

discovery-data/latest/elastic-backup-restore.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ function clean_up(){
239239
else\
240240
break;\
241241
fi;\
242-
done && \
243-
curl -XPUT -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_cluster/settings" -H "Content-Type: application/json" -d"{\"transient\": {\"discovery.zen.commit_timeout\": null, \"discovery.zen.publish_timeout\": null}}"' ${OC_ARGS} -c elasticsearch
242+
done ' ${OC_ARGS} -c elasticsearch
244243
echo
245244

245+
if [ $(compare_version ${WD_VERSION} "5.0.0") -lt 0 ]; then
246+
run_cmd_in_pod ${ELASTIC_POD} 'export ELASTIC_ENDPOINT=https://localhost:9200 && \
247+
curl -XPUT -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_cluster/settings" -H "Content-Type: application/json" -d"{\"transient\": {\"discovery.zen.commit_timeout\": null, \"discovery.zen.publish_timeout\": null}}"' ${OC_ARGS} -c elasticsearch
248+
fi
249+
246250
if [ $(compare_version ${WD_VERSION} "4.7.0") -lt 0 ] ; then
247251
start_minio_port_forward
248252
${MC} "${MC_OPTS[@]}" rm --recursive --force --dangerous wdminio/${ELASTIC_BACKUP_BUCKET}/ > /dev/null
@@ -409,13 +413,19 @@ EOF
409413
run_cmd_in_pod ${ELASTIC_POD} "tar ${ELASTIC_TAR_OPTIONS[*]} -xmpf /workdir/shared_storage/${ELASTIC_BACKUP} -C /workdir/shared_storage && rm -f /workdir/shared_storage/${ELASTIC_BACKUP}" ${OC_ARGS} -c elasticsearch
410414
fi
411415
brlog "INFO" "Start Restoring snapshot"
416+
412417
run_cmd_in_pod ${ELASTIC_POD} 'export S3_HOST='${S3_SVC}' && export S3_PORT='${S3_PORT}' && export S3_ELASTIC_BACKUP_BUCKET='${ELASTIC_BACKUP_BUCKET}' && export ELASTIC_ENDPOINT=https://localhost:9200 && \
413418
S3_IP=$(curl -kv "https://$S3_HOST:$S3_PORT/minio/health/ready" 2>&1 | grep Connected | sed -E "s/.*\(([0-9.]+)\).*/\1/g") && \
414-
curl -XPUT --fail -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_cluster/settings" -H "Content-Type: application/json" -d"{\"transient\": {\"discovery.zen.commit_timeout\": \"'${ELASTIC_REQUEST_TIMEOUT}'\", \"discovery.zen.publish_timeout\": \"'${ELASTIC_REQUEST_TIMEOUT}'\"}}" && \
415419
curl -XDELETE --fail -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_all?master_timeout='${ELASTIC_REQUEST_TIMEOUT}'" && \
416420
curl -XDELETE --fail -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/.*?master_timeout='${ELASTIC_REQUEST_TIMEOUT}'" && \
417421
curl -XPUT --fail -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_snapshot/'${ELASTIC_REPO}'?master_timeout='${ELASTIC_REQUEST_TIMEOUT}'" -H "Content-Type: application/json" '"${REPO_CONFIGURATION}"' && \
418422
curl -XPOST --fail -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_snapshot/'${ELASTIC_REPO}'/'${ELASTIC_SNAPSHOT}'/_restore?master_timeout='${ELASTIC_REQUEST_TIMEOUT}'" -H "Content-Type: application/json" -d"{\"indices\": \"*,-application_logs-*\", \"expand_wildcards\": \"all\", \"allow_no_indices\": \"true\"}" | grep accepted && echo ' ${OC_ARGS} -c elasticsearch
423+
424+
if [ $(compare_version ${WD_VERSION} "5.0.0") -lt 0 ]; then
425+
run_cmd_in_pod ${ELASTIC_POD} 'export ELASTIC_ENDPOINT=https://localhost:9200 && \
426+
curl -XPUT --fail -s -k -u ${ELASTIC_USER}:${ELASTIC_PASSWORD} "${ELASTIC_ENDPOINT}/_cluster/settings" -H "Content-Type: application/json" -d"{\"transient\": {\"discovery.zen.commit_timeout\": \"'${ELASTIC_REQUEST_TIMEOUT}'\", \"discovery.zen.publish_timeout\": \"'${ELASTIC_REQUEST_TIMEOUT}'\"}}" ' ${OC_ARGS} -c elasticsearch
427+
fi
428+
419429
brlog "INFO" "Sent restore request"
420430
waited_seconds=0
421431
total_shards=0

discovery-data/latest/lib/function.bash

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export BACKUP_VERSION_FILE="tmp/version.txt"
55
export DATASTORE_ARCHIVE_OPTION="${DATASTORE_ARCHIVE_OPTION--z}"
66
export BACKUP_RESTORE_LOG_DIR="${BACKUP_RESTORE_LOG_DIR:-wd-backup-restore-logs-$(date "+%Y%m%d_%H%M%S")}"
77
export BACKUP_RESTORE_SA="${BACKUP_RESTORE_SA:-wd-discovery-backup-restore-sa}"
8+
export BACKUP_RESTORE_RBAC_LABEL_KEY="${BACKUP_RESTORE_RBAC_LABEL_KEY:-discovery.ibm.com/component}"
9+
export BACKUP_RESTORE_RABC_LABEL_VALUE="${BACKUP_RESTORE_RBAC_LABEL_VALUE:-backup-restore-scripts}"
810

911
case "${BACKUP_RESTORE_LOG_LEVEL}" in
1012
"ERROR") export LOG_LEVEL_NUM=0;;
@@ -41,8 +43,17 @@ trap_add(){
4143
}
4244

4345
trap_remove(){
46+
# Remove $1 command from 'trap_commands'.
4447
trap_commands=( "${trap_commands[@]/$1}" )
45-
trap "${trap_commands}" 0 1 2 3 15
48+
49+
# NOTE: if 'trap_commands' is empty, "${trap_commands}" cause unbound variable error when set -u.
50+
if [[ -z "${trap_commands[@]}" ]]; then
51+
cmd=""
52+
else
53+
printf -v joined '%s;' "${trap_commands[@]}"
54+
cmd="$(echo -n "${joined%;}")"
55+
fi
56+
trap "${cmd}" 0 1 2 3 15
4657
}
4758

4859
disable_trap(){
@@ -340,6 +351,7 @@ wait_cmd(){
340351
done
341352
}
342353

354+
# NOTE: This does not detect error exit code.
343355
fetch_cmd_result(){
344356
set +e
345357
local pod=$1
@@ -734,6 +746,11 @@ run_core_init_db_job(){
734746
done
735747
}
736748

749+
# Get the file path where it only stores the last result of 'run_cmd_in_pod'.
750+
get_last_cmd_result_file() {
751+
echo "${BACKUP_RESTORE_LOG_DIR}/last_cmd_result.log"
752+
}
753+
737754
run_cmd_in_pod(){
738755
local pod="$1"
739756
shift
@@ -759,7 +776,12 @@ EOF
759776
_oc_cp ${TMP_WORK_DIR}/${WD_CMD_FILE} ${pod}:/tmp/${WD_CMD_FILE} $@
760777
oc exec $@ ${pod} -- bash -c "rm -rf /tmp/${WD_CMD_COMPLETION_TOKEN} && /tmp/${WD_CMD_FILE} &"
761778
wait_cmd ${pod} $@
762-
oc exec $@ ${pod} -- bash -c "cat /tmp/${WD_CMD_LOG}; rm -rf /tmp/${WD_CMD_FILE} /tmp/${WD_CMD_LOG} /tmp/${WD_CMD_COMPLETION_TOKEN}" >> "${BACKUP_RESTORE_LOG_DIR}/${CURRENT_COMPONENT}.log"
779+
780+
# Create an intermediate log file which only stores the last command result.
781+
LAST_CMD_RESULT_FILE=$(get_last_cmd_result_file)
782+
oc exec $@ ${pod} -- bash -c "cat /tmp/${WD_CMD_LOG}; rm -rf /tmp/${WD_CMD_FILE} /tmp/${WD_CMD_LOG} /tmp/${WD_CMD_COMPLETION_TOKEN}" > "$LAST_CMD_RESULT_FILE"
783+
cat "$LAST_CMD_RESULT_FILE" >> "${BACKUP_RESTORE_LOG_DIR}/${CURRENT_COMPONENT}.log"
784+
763785
files=$(fetch_cmd_result ${pod} "ls /tmp" $@)
764786
if echo "${files}" | grep "${WD_CMD_FAILED_TOKEN}" > /dev/null ; then
765787
oc exec $@ ${pod} -- bash -c "rm -f /tmp/${WD_CMD_FAILED_TOKEN}"
@@ -768,6 +790,16 @@ EOF
768790
fi
769791
}
770792

793+
# Get the last result (stdout) of 'run_cmd_in_pod'
794+
get_last_cmd_result_in_pod(){
795+
LAST_CMD_RESULT_FILE=$(get_last_cmd_result_file)
796+
if [ ! -f "$LAST_CMD_RESULT_FILE" ]; then
797+
echo ""
798+
else
799+
cat "$LAST_CMD_RESULT_FILE"
800+
fi
801+
}
802+
771803
run_script_in_pod(){
772804
local pod="$1"
773805
shift
@@ -1026,7 +1058,9 @@ require_mt_mt_migration(){
10261058

10271059
get_primary_pg_pod(){
10281060
local wd_version=${WD_VERSION:-$(get_version)}
1029-
if [ $(compare_version "${wd_version}" "4.0.0") -ge 0 ] ; then
1061+
if [ $(compare_version "${wd_version}" "5.0.0") -ge 0 ] ; then
1062+
echo "$(oc get pod ${OC_ARGS} -l "icpdsupport/podSelector=discovery-cn-postgres,role=primary" -o jsonpath='{.items[0].metadata.name}')"
1063+
elif [ $(compare_version "${wd_version}" "4.0.0") -ge 0 ] ; then
10301064
echo "$(oc get pod ${OC_ARGS} -l "postgresql=${TENANT_NAME}-discovery-cn-postgres,role=primary" -o jsonpath='{.items[0].metadata.name}')"
10311065
else
10321066
for POD in $(oc get pods ${OC_ARGS} -o jsonpath='{.items[*].metadata.name}' -l tenant=${TENANT_NAME},component=stolon-keeper) ; do
@@ -1133,6 +1167,52 @@ check_datastore_available(){
11331167
brlog "INFO" "All data store service are available"
11341168
}
11351169

1170+
# Get elastic indices and return its version as a string. Return the oldest index version.
1171+
# Assume there are only version 6 or 7 indices in the cluster.
1172+
get_elastic_version() {
1173+
ELASTIC_POD=$(get_elastic_pod)
1174+
run_script_in_pod ${ELASTIC_POD} "${SCRIPT_DIR}/reindex_es6_indices.sh" "--dry-run" -c elasticsearch ${OC_ARGS}
1175+
result=$(get_last_cmd_result_in_pod)
1176+
1177+
if echo "$result" | grep -q "Skip ElasticSearch 6 index"; then
1178+
echo "ES6"
1179+
elif echo "$result" | grep -q "Skip ElasticSearch 7 index"; then
1180+
echo "ES7"
1181+
elif echo "$result" | grep -q "ElasticSearch has no index"; then
1182+
echo "NoIndex"
1183+
else
1184+
echo "Unknown"
1185+
fi
1186+
}
1187+
1188+
validate_elastic_version() {
1189+
ELASTIC_VERSION="${1:-$(get_elastic_version)}"
1190+
1191+
if [[ ${ELASTIC_VERSION} = "ES6" ]]; then
1192+
brlog "WARN" "Elasticsearch 6 detected."
1193+
if [[ ${IGNORE_OLD_INDEX} = "true" ]]; then
1194+
brlog "WARN" "Ignoring old index."
1195+
elif [[ ${REINDEX_OLD_INDEX} = "true" ]]; then
1196+
brlog "INFO" "Elasticsearch 6 will be reindexed after quiescing."
1197+
else
1198+
brlog "ERROR" "Detected old index created in ElasticSearch 6 that is not supported Watson Discovery 4.8.x. They have to be reindexed if you restore to 4.8.x or higher. Reindex actually won't change your data, but it takes time. Run backup script with '--reindex-old-index' option if you reindex them. You can proceed backup without reindex, but you can't restore the backup data to 4.8.x. If you would like to ignore the error, run backup script with '--ignore-old-index' option."
1199+
exit 1
1200+
fi
1201+
fi
1202+
}
1203+
1204+
# Reindex elastic search indices from version 6 to 7.
1205+
reindex_elastic_es6() {
1206+
brlog "INFO" "Reindexing ..."
1207+
run_script_in_pod ${ELASTIC_POD} "${SCRIPT_DIR}/reindex_es6_indices.sh" "" -c elasticsearch ${OC_ARGS}
1208+
brlog "INFO" "Reindex completed. Waiting for ElasticSearch status to be green ..."
1209+
# Wait a few moments for elastic search to be ready after the reindex.
1210+
# TODO: implement waiting logic inside of reindex_es6_indices.sh, and remove the sleep below from this function.
1211+
sleep 60
1212+
check_elastic_available || { brlog "ERROR" "ElasticSearch is unavailable"; exit 1; }
1213+
}
1214+
1215+
11361216
check_etcd_available(){
11371217
setup_etcd_env
11381218
ETCD_POD=$(oc get pods ${OC_ARGS} -o jsonpath="{.items[0].metadata.name}" -l etcd_cluster=${TENANT_NAME}-discovery-etcd)
@@ -1400,15 +1480,17 @@ create_service_instance(){
14001480

14011481
create_service_account(){
14021482
local service_account="$1"
1403-
if [ -n "$(oc get sa ${service_account})" ] ; then
1483+
if [ -n "$(oc get sa "${service_account}")" ] ; then
14041484
brlog "INFO" "Service Account ${service_account} already exists"
14051485
else
14061486
brlog "INFO" "Create Service Account for scripts: ${service_account}"
14071487
local namespace="${NAMESPACE:-$(oc config view --minify --output 'jsonpath={..namespace}')}"
1408-
oc ${OC_ARGS} create sa ${service_account}
1409-
oc ${OC_ARGS} policy add-role-to-user admin system:serviceaccount:${namespace}:${service_account}
1488+
oc ${OC_ARGS} create sa "${service_account}"
1489+
oc ${OC_ARGS} label sa "${service_account}" "${BACKUP_RESTORE_RBAC_LABEL_KEY}"="${BACKUP_RESTORE_RABC_LABEL_VALUE}"
1490+
oc ${OC_ARGS} policy add-role-to-user admin "system:serviceaccount:${namespace}:${service_account}"
14101491
oc delete clusterrolebinding "${service_account}-cluster-rb" --ignore-not-found
1411-
oc ${OC_ARGS} create clusterrolebinding "${service_account}-cluster-rb" --clusterrole cluster-admin --serviceaccount ${namespace}:${service_account} 2>&1
1492+
oc ${OC_ARGS} create clusterrolebinding "${service_account}-cluster-rb" --clusterrole cluster-admin --serviceaccount "${namespace}:${service_account}" 2>&1
1493+
oc ${OC_ARGS} label clusterrolebinding "${service_account}-cluster-rb" "${BACKUP_RESTORE_RBAC_LABEL_KEY}"="${BACKUP_RESTORE_RABC_LABEL_VALUE}"
14121494
if [ -n "$(oc ${OC_ARGS} get role discovery-operator-role --ignore-not-found)" ] ; then
14131495
# This is 2.2.1 install. Link operator role to this service account to get permission of discovery resources
14141496
cat <<EOF | oc ${OC_ARGS} apply -f -
@@ -1417,6 +1499,8 @@ apiVersion: rbac.authorization.k8s.io/v1
14171499
kind: RoleBinding
14181500
metadata:
14191501
name: ${service_account}-rb
1502+
labels:
1503+
${BACKUP_RESTORE_RBAC_LABEL_KEY}: ${BACKUP_RESTORE_RABC_LABEL_VALUE}
14201504
roleRef:
14211505
apiGroup: rbac.authorization.k8s.io
14221506
kind: Role
@@ -1448,9 +1532,7 @@ get_oc_token(){
14481532

14491533
delete_service_account(){
14501534
local service_account="$1"
1451-
oc ${OC_ARGS} delete rolebinding ${service_account}-rb --ignore-not-found
1452-
oc ${OC_ARGS} delete sa ${service_account} --ignore-not-found
1453-
oc ${OC_ARGS} delete clusterrolebinding ${service_account}-cluster-rb --ignore-not-found
1535+
oc ${OC_ARGS} delete rolebinding,clusterrolebinding,sa -l "${BACKUP_RESTORE_RBAC_LABEL_KEY}"="${BACKUP_RESTORE_RABC_LABEL_VALUE}" --ignore-not-found
14541536
trap_remove "brlog 'INFO' 'You currently oc login as a scripts ServiceAccount. You can rerun scripts with this. Please delete ServiceAccount ${service_account} and clusterrolebinding ${service_account}-cluster-rb when you complete backup or restore'"
14551537
trap_remove "brlog 'INFO' 'brlog 'INFO' 'Please delete rolebinding ${service_account}-rb when you delete ServiceAccount'"
14561538
brlog "INFO" "Deleted scripts service account: ${service_account}"

discovery-data/latest/reindex_es6_indices.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
set -euo pipefail
44

55
TMP_WORK_DIR="/tmp/elastic-workdir"
6+
DRY_RUN=false # If this is true, this script will not reindex any indices. It just print indices versions.
7+
8+
function show_help() {
9+
cat <<EOS
10+
Reindex elastic search indices from version 6 to version 7.
11+
If version 7 indices are detected, this script does nothing.
12+
If version 6 indices are detected, this script will perform reindexing to update the indices as version 7.
13+
14+
usage: $0 [options]
15+
16+
options:
17+
-h, --help Print help info.
18+
--dry-run [Optional] If specified, this script does not perform reindexing. It will just print detected indices versions to stdout.
19+
Use this option if you only want to check your elastic search indices versions.
20+
EOS
21+
}
622

723
function generate_new_settings() {
824
local index="$1"
@@ -141,6 +157,7 @@ function clone_index() {
141157
clone_body_json=clone_body.json
142158
echo "${clone_body}" > "${clone_body_json}"
143159

160+
# TODO validate clone result.
144161
curl -sSfk -u "${ELASTIC_USER}:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" -XPOST "${ELASTIC_ENDPOINT}/${src_index}/_clone/${dst_index}" -d@"${TMP_WORK_DIR}/${clone_body_json}"
145162
echo ""
146163

@@ -178,7 +195,39 @@ function remove_index_if_exists(){
178195
fi
179196
}
180197

198+
# Parse argument.
199+
while [[ $# -gt 0 ]]; do
200+
OPT=$1
201+
case $OPT in
202+
-h | --help)
203+
show_help
204+
exit 0
205+
;;
206+
--dry-run)
207+
DRY_RUN=true
208+
shift 1
209+
;;
210+
-- | -)
211+
shift 1
212+
param+=("$@")
213+
break
214+
;;
215+
-*)
216+
echo "illegal option: $1"
217+
exit 1
218+
;;
219+
*)
220+
echo "illegal argument: $1"
221+
exit 1
222+
;;
223+
esac
224+
done
225+
181226
# Main logic start from here
227+
if [[ ${DRY_RUN} = "true" ]]; then
228+
echo "'--dry-run' specified. Running script in dry running mode. No reindex will be performed."
229+
fi
230+
182231
trap 'if [ $? -ne 0 ] ; then echo "Error: Please contact support. Do not run this scripts again."; fi' 0 1 2 3 15
183232
rm -rf "${TMP_WORK_DIR}"
184233
mkdir -p "${TMP_WORK_DIR}"
@@ -208,6 +257,12 @@ if [ "${index_count}" = "0" ] ; then
208257
exit 0
209258
fi
210259

260+
distribution="$(curl -sSkf -u "${ELASTIC_USER}:${ELASTIC_PASSWORD}" "${ELASTIC_ENDPOINT}" | jq -r .version.distribution)"
261+
if [ "$distribution" = "opensearch" ] ; then
262+
echo "Opensearch distribution is being used. There is no need for reindexing."
263+
exit 0
264+
fi
265+
211266
echo "Getting index list"
212267
indices="$(curl -sSkf -u "${ELASTIC_USER}:${ELASTIC_PASSWORD}" "${ELASTIC_ENDPOINT}/_cat/indices?h=index")"
213268

@@ -228,6 +283,8 @@ for index in ${indices} ; do
228283
version="$(curl -sSkf -u "${ELASTIC_USER}:${ELASTIC_PASSWORD}" "${ELASTIC_ENDPOINT}/${index}/_settings" | jq -r .[].settings.index.version.created)"
229284
if [[ ${version} = 7* ]]; then
230285
echo "[${count} / ${total}] Skip ElasticSearch 7 index: ${index}"
286+
elif [[ ${version} = 6* && ${DRY_RUN} = "true" ]]; then
287+
echo "[${count} / ${total}] Skip ElasticSearch 6 index: ${index}"
231288
elif [[ ${version} = 6* ]]; then
232289
echo "[${count} / ${total}] ElasticSearch 6 index found: ${index}"
233290
echo "----------------------------"

discovery-data/latest/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
The Backup and Restore Scripts for the Watson Discovery on CP4D.
2-
Scripts Version: 4.8.5
2+
Scripts Version: 5.0.0

0 commit comments

Comments
 (0)