Skip to content

Commit f9406ef

Browse files
authored
Merge pull request #269 from yuki462-b/update-discovery-scripts-for-5.1.0
feat: updating backup restore scripts for WD 5.1.0.
2 parents 60a0423 + 9414048 commit f9406ef

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

discovery-data/latest/lib/function.bash

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,17 +926,21 @@ get_pg_configmap(){
926926
local wd_version=${WD_VERSION:-$(get_version)}
927927
if [ $(compare_version "${wd_version}" "2.2.1") -le 0 ] ; then
928928
echo $(oc get ${OC_ARGS} configmap -l tenant=${TENANT_NAME},app.kubernetes.io/component=postgres-cxn -o jsonpath="{.items[0].metadata.name}")
929-
else
929+
elif [ $(compare_version "${wd_version}" "5.1.0") -lt 0 ] ; then
930930
echo $(oc get ${OC_ARGS} configmap -l tenant=${TENANT_NAME},app=cn-postgres -o jsonpath="{.items[0].metadata.name}")
931+
else
932+
echo $(oc get ${OC_ARGS} configmap -l tenant=${TENANT_NAME},app=cn-postgres16 -o jsonpath="{.items[0].metadata.name}")
931933
fi
932934
}
933935

934936
get_pg_secret(){
935937
local wd_version=${WD_VERSION:-$(get_version)}
936938
if [ $(compare_version "${wd_version}" "2.2.1") -le 0 ] ; then
937939
echo $(oc ${OC_ARGS} get secret -l tenant=${TENANT_NAME},cr=${TENANT_NAME}-discovery-postgres -o jsonpath="{.items[*].metadata.name}")
938-
else
940+
elif [ $(compare_version "${wd_version}" "5.1.0") -lt 0 ] ; then
939941
echo $(oc ${OC_ARGS} get secret -l tenant=${TENANT_NAME},run=cn-postgres -o jsonpath="{.items[*].metadata.name}" | tr '[[:space:]]' '\n' | grep "cn-postgres-wd")
942+
else
943+
echo $(oc ${OC_ARGS} get secret -l tenant=${TENANT_NAME},run=cn-postgres16 -o jsonpath="{.items[*].metadata.name}" | tr '[[:space:]]' '\n' | grep "cn-postgres16-wd")
940944
fi
941945
}
942946

@@ -1124,7 +1128,9 @@ require_mt_mt_migration(){
11241128

11251129
get_primary_pg_pod(){
11261130
local wd_version=${WD_VERSION:-$(get_version)}
1127-
if [ $(compare_version "${wd_version}" "5.0.0") -ge 0 ] ; then
1131+
if [ $(compare_version "${wd_version}" "5.1.0") -ge 0 ] ; then
1132+
echo "$(oc get pod ${OC_ARGS} -l "icpdsupport/podSelector=discovery-cn-postgres16,role=primary" -o jsonpath='{.items[0].metadata.name}')"
1133+
elif [ $(compare_version "${wd_version}" "5.0.0") -ge 0 ] ; then
11281134
echo "$(oc get pod ${OC_ARGS} -l "icpdsupport/podSelector=discovery-cn-postgres,role=primary" -o jsonpath='{.items[0].metadata.name}')"
11291135
elif [ $(compare_version "${wd_version}" "4.0.0") -ge 0 ] ; then
11301136
echo "$(oc get pod ${OC_ARGS} -l "postgresql=${TENANT_NAME}-discovery-cn-postgres,role=primary" -o jsonpath='{.items[0].metadata.name}')"
@@ -1181,9 +1187,9 @@ launch_s3_pod(){
11811187
if [ -n "${DISABLE_MC_MULTIPART:+UNDEF}" ] ; then add_env_to_job_yaml "DISABLE_MC_MULTIPART" "${DISABLE_MC_MULTIPART}" "${S3_JOB_FILE}"; fi
11821188
add_env_to_job_yaml "TZ" "${TZ_OFFSET}" "${S3_JOB_FILE}"
11831189
add_env_to_job_yaml "WD_VERSION" "${wd_version}" "${S3_JOB_FILE}"
1190+
add_env_to_job_yaml "S3_BUCKETS" "${S3_BUCKETS}" "${S3_JOB_FILE}"
11841191
add_volume_to_job_yaml "backup-restore-workspace" "${TMP_PVC_NAME:-emptyDir}" "${S3_JOB_FILE}"
11851192
if [ $(compare_version ${wd_version} "4.7.0") -ge 0 ] ; then
1186-
BUCKET_SUFFIX="$(get_bucket_suffix)"
11871193
S3_CERT_SECRET=$(oc get secret -l "icpdsupport/addOnId=discovery,icpdsupport/app=s3-cert-secret,tenant=${TENANT_NAME}" -o jsonpath="{.items[0].metadata.name}")
11881194
add_secret_volume_to_job_yaml "tls-secret" "${S3_CERT_SECRET}" "${S3_JOB_FILE}"
11891195
add_volume_mount_to_job_yaml "tls-secret" "${S3_CERT_MOUNT_PATH}" "${S3_JOB_FILE}"
@@ -1208,6 +1214,7 @@ setup_s3_env(){
12081214
S3_CONFIGMAP=${S3_CONFIGMAP:-$(oc get ${OC_ARGS} cm -l "app.kubernetes.io/component=s3,tenant=${TENANT_NAME}" -o jsonpath="{.items[*].metadata.name}")}
12091215
S3_SECRET=${S3_SECRET:-$(oc ${OC_ARGS} get secret -l "tenant=${TENANT_NAME},run=s3-auth" -o jsonpath="{.items[*].metadata.name}" | tr -s '[[:space:]]' '\n' | grep s3)}
12101216
fi
1217+
BUCKET_SUFFIX="${BUCKET_SUFFIX:-$(get_bucket_suffix)}"
12111218
S3_SVC=${S3_SVC:-$(oc extract ${OC_ARGS} configmap/${S3_CONFIGMAP} --keys=host --to=- 2> /dev/null)}
12121219
if [[ "${S3_SVC}" == *"."* ]] ; then
12131220
array=(${S3_SVC//./ })
@@ -1222,6 +1229,7 @@ setup_s3_env(){
12221229
S3_FORWARD_PORT=${S3_FORWARD_PORT:-39001}
12231230
S3_ENDPOINT_URL=${S3_ENDPOINT_URL:-https://localhost:$S3_FORWARD_PORT}
12241231
S3_JOB_FILE="${SCRIPT_DIR}/src/s3-backup-restore-job.yml"
1232+
S3_BUCKETS=${S3_BUCKETS:-$(get_s3_buckets)}
12251233
}
12261234

12271235
check_datastore_available(){
@@ -1261,7 +1269,7 @@ validate_elastic_version() {
12611269
elif [[ ${REINDEX_OLD_INDEX} = "true" ]]; then
12621270
brlog "INFO" "Elasticsearch 6 will be reindexed after quiescing."
12631271
else
1264-
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."
1272+
brlog "ERROR" "Detected old index created in ElasticSearch 6 that is not supported in Watson Discovery 4.8.x. They have to be reindexed if you want to restore to 4.8.x or higher. Reindex actually won't change your data, but it takes time. Run the backup script with '--reindex-old-index' option if you want to reindex them. You can proceed the 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."
12651273
exit 1
12661274
fi
12671275
fi
@@ -1711,4 +1719,21 @@ restart_job(){
17111719
fi
17121720
done
17131721
done
1722+
}
1723+
1724+
get_s3_buckets(){
1725+
local s3_buckets
1726+
if [ $(compare_version ${wd_version} "4.7.0") -lt 0 ] ; then
1727+
s3_buckets=$(oc get ${OC_ARGS} miniocluster ${TENANT_NAME}-minio -o jsonpath='{.spec.buckets[*].name}')
1728+
else
1729+
bucket_job=$(oc get ${OC_ARGS} job -l "discovery.ibm.com/component=s3-bucket-job,tenant=${TENANT_NAME}" -o jsonpath='{.items[0].metadata.name}')
1730+
s3_buckets=$(oc get ${OC_ARGS} job "${bucket_job}" -o jsonpath='{.spec.template.spec.containers[0].env[?(@.name=="S3_BUCKETS")].value}')
1731+
fi
1732+
# sdu is not in this list. Add manually.
1733+
# BUCKET_SUFFIX is empty in version < 4.7.0
1734+
if ! echo "${s3_buckets}" | grep "sdu${BUCKET_SUFFIX}" > /dev/null ; then
1735+
echo -n "${s3_buckets} sdu${BUCKET_SUFFIX}"
1736+
else
1737+
echo -n "${s3_buckets}"
1738+
fi
17141739
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ if [[ -z "${LOG_LEVEL_NUM:+UNDEF}" ]] || [ "$LOG_LEVEL_NUM" -ge 3 ]; then
123123
MIRROR_OPTS+=("--debug")
124124
fi
125125

126-
BUCKET_SUFFIX="$(get_bucket_suffix)"
127-
128126
# backup
129127
if [ "${COMMAND}" = "backup" ] ; then
130128
brlog "INFO" "Start backup minio"
@@ -136,8 +134,11 @@ if [ "${COMMAND}" = "backup" ] ; then
136134
EXCLUDE_OBJECTS+=$'\n'
137135
EXCLUDE_OBJECTS+="$(cat "${SCRIPT_DIR}/src/mcg_exclude_paths")"
138136
fi
139-
for bucket in $("${MC}" "${MC_OPTS[@]}" ls wdminio | sed ${SED_REG_OPT} "s|.*[0-9]+B\ (.*)/.*|\1|g" | grep -v ${ELASTIC_BACKUP_BUCKET})
137+
for bucket in ${S3_BUCKETS//,/ }
140138
do
139+
if [ "${bucket}" == "${ELASTIC_BACKUP_BUCKET}" ] ; then
140+
continue
141+
fi
141142
EXTRA_MC_MIRROR_COMMAND=()
142143
ORG_IFS=${IFS}
143144
IFS=$'\n'

discovery-data/latest/src/minio-backup-restore-in-pod.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ if "${DISABLE_MC_MULTIPART:-true}" ; then
4343
fi
4444

4545
BUCKET_SUFFIX="${BUCKET_SUFFIX:-}"
46+
S3_BUCKETS=${S3_BUCKETS:-}
4647

4748
# backup
4849
if [ "${COMMAND}" = "backup" ] ; then
@@ -54,8 +55,11 @@ if [ "${COMMAND}" = "backup" ] ; then
5455
EXCLUDE_OBJECTS+=$'\n'
5556
EXCLUDE_OBJECTS+="$(cat "${SCRIPT_DIR}/src/mcg_exclude_paths")"
5657
fi
57-
for bucket in $("${MC}" "${MC_OPTS[@]}" ls wdminio | sed ${SED_REG_OPT} "s|.*[0-9]+B\ (.*)/.*|\1|g" | grep -v ${ELASTIC_BACKUP_BUCKET})
58+
for bucket in ${S3_BUCKETS//,/ }
5859
do
60+
if [ "${bucket}" == "${ELASTIC_BACKUP_BUCKET}" ] ; then
61+
continue
62+
fi
5963
EXTRA_MC_MIRROR_COMMAND=()
6064
ORG_IFS=${IFS}
6165
IFS=$'\n'

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: 5.0.3
2+
Scripts Version: 5.1.0

0 commit comments

Comments
 (0)