Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions addons/elasticsearch/dataprotection/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trap handle_exit EXIT

function getToolConfigValue() {
local var=$1
cat $toolConfig | grep "$var[[:space:]]*=" | awk '{print $NF}'
cat $toolConfig | grep "${var}[[:space:]]*=" | awk '{print $NF}'
}

s3_endpoint=$(getToolConfigValue endpoint)
Expand Down Expand Up @@ -94,6 +94,18 @@ done
echo "INFO: All nodes keystore configured, reloading secure settings"
curl -X POST "${ES_ENDPOINT}/_nodes/reload_secure_settings"

# Wait for secure settings to be reloaded and plugins to be loaded
echo "INFO: Waiting for nodes to be ready after reloading secure settings..."
sleep 10

# Verify that S3 repository plugin is available
echo "INFO: Checking if S3 repository plugin is available..."
if curl -s -f "${ES_ENDPOINT}/_snapshot" | grep -q 's3'; then
echo "INFO: S3 repository plugin is available"
else
echo "WARNING: S3 repository plugin may not be available, attempting to create repository anyway"
fi

# DP_BACKUP_BASE_PATH is the path to the backup directory
# if the target policy is All, the path pattern is: /${namespace}/${clusterName}-${clusterUID}/${componentDef}/${backupName}/${podName}
# if the target policy is Any, the path pattern is: /${namespace}/${clusterName}-${clusterUID}/${componentDef}/${backupName}
Expand All @@ -105,7 +117,7 @@ base_path=${base_path#*/}

function wait_for_snapshot_completion() {
while true; do
state=$(curl -s -X GET "${ES_ENDPOINT}/_snapshot/${REPOSITORY}/${DP_BACKUP_NAME}?sort=name&pretty" | grep -w state | awk '{print $NF}' | tr -d ',"')
state=$(curl -s -X GET "${ES_ENDPOINT}/_snapshot/${REPOSITORY}/${DP_BACKUP_NAME}?pretty" | grep -w state | awk '{print $NF}' | tr -d ',"')
if [ "$state" == "SUCCESS" ]; then
echo "INFO: backup success"
break
Expand Down
50 changes: 40 additions & 10 deletions addons/elasticsearch/dataprotection/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trap handle_exit EXIT

function getToolConfigValue() {
local var=$1
cat $toolConfig | grep "$var[[:space:]]*=" | awk '{print $NF}'
cat $toolConfig | grep "${var}[[:space:]]*=" | awk '{print $NF}'
}

s3_endpoint=$(getToolConfigValue endpoint)
Expand Down Expand Up @@ -93,6 +93,25 @@ done
echo "INFO: All nodes keystore configured for restore, reloading secure settings"
curl -X POST "${ES_ENDPOINT}/_nodes/reload_secure_settings"

# Get Elasticsearch major version (call once at the beginning)
function get_es_major_version() {
local version_info=$(curl -s ${BASIC_AUTH} -X GET "${ES_ENDPOINT}/_nodes" | grep -o '"version":"[^"]*"' | head -1 | cut -d'"' -f4)
if [ -z "$version_info" ]; then
echo "ERROR: Failed to get Elasticsearch version" >&2
return 1
fi
# Extract major version (e.g., "7.10.1" -> "7")
echo "$version_info" | cut -d'.' -f1
}

echo "INFO: Getting Elasticsearch version"
es_major_version=$(get_es_major_version)
if [ $? -ne 0 ]; then
echo "ERROR: Failed to get Elasticsearch version"
exit 1
fi
echo "INFO: Detected Elasticsearch major version: $es_major_version"

cat > /tmp/repository.json<< EOF
{
"type": "s3",
Expand Down Expand Up @@ -120,14 +139,20 @@ function enable_indexing_and_geoip() {
exit 1
;;
esac
curl -f -X PUT "${ES_ENDPOINT}/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent": {
"ingest.geoip.downloader.enabled": '$switch',
"indices.lifecycle.history_index_enabled": '$switch'
}
}
'

# Check if version is less than 8.0
if [ "$es_major_version" -lt 8 ]; then
echo "WARNING: Elasticsearch version is $es_major_version.x, which does not support dynamically updating 'indices.lifecycle.history_index_enabled' and 'ingest.geoip.downloader.enabled'. "
else
curl -f -X PUT "${ES_ENDPOINT}/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
"persistent": {
"ingest.geoip.downloader.enabled": '$switch',
"indices.lifecycle.history_index_enabled": '$switch'
}
}
'
fi
}

function switch_ilm() {
Expand Down Expand Up @@ -258,7 +283,12 @@ fi
enable_destructive_requires_name false

# Delete all existing data streams on the cluster.
curl -f -s -X DELETE "${ES_ENDPOINT}/_data_stream/*?expand_wildcards=all&pretty"
# expand_wildcards parameter is not supported in ES 7.x for data stream deletion
if [ "$es_major_version" -lt 8 ]; then
curl -f -s -X DELETE "${ES_ENDPOINT}/_data_stream/*?pretty"
else
curl -f -s -X DELETE "${ES_ENDPOINT}/_data_stream/*?expand_wildcards=all&pretty"
fi

# Delete all existing indices on the cluster.
curl -f -s -X DELETE "${ES_ENDPOINT}/*?expand_wildcards=all&pretty"
Expand Down
24 changes: 21 additions & 3 deletions addons/elasticsearch/plugins/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ FROM alpine:3.19.1

WORKDIR /plugins

RUN wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.8.2/elasticsearch-analysis-ik-8.8.2.zip \
&& unzip elasticsearch-analysis-ik-8.8.2.zip -d ./analysis-ik/ \
&& rm elasticsearch-analysis-ik-8.8.2.zip
# Install all plugins
RUN set -e && \
# IK plugins for all versions \
for version in 6.8.23 7.7.1 7.8.1 7.10.1 8.1.3 8.8.2 8.15.5; do \
echo "Installing IK plugin for Elasticsearch $version"; \
mkdir -p ./${version}/ik && \
wget -q https://release.infinilabs.com/analysis-ik/stable/elasticsearch-analysis-ik-${version}.zip && \
unzip -q elasticsearch-analysis-ik-${version}.zip -d ./${version}/ik/ && \
rm elasticsearch-analysis-ik-${version}.zip; \
done && \
\
# S3 plugins for 6.x and 7.x (8.x has it built-in) \
for version in 6.8.23 7.7.1 7.8.1 7.10.1; do \
echo "Installing S3 plugin for Elasticsearch $version"; \
mkdir -p ./${version}/s3 && \
wget -q https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-s3/repository-s3-${version}.zip && \
unzip -q repository-s3-${version}.zip -d ./${version}/s3/ && \
rm repository-s3-${version}.zip; \
done && \
\
echo "All plugins installed successfully"
36 changes: 27 additions & 9 deletions addons/elasticsearch/scripts/install-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ if [ ! -d $src_plugins_dir ]; then
exit 0
fi

# [root@35bde36fc986 elasticsearch]# elasticsearch --version
# Version: 7.10.1, Build: default/docker/1c34507e66d7db1211f66f3513706fdf548736aa/2020-12-05T01:00:33.671820Z, JVM: 15.0.1
ELASTICSEARCH_VERSION=$(elasticsearch --version | grep "Version:" | awk '{print $2}' | sed 's/,.*//')

if [ -z "$ELASTICSEARCH_VERSION" ]; then
echo "ELASTICSEARCH_VERSION is not set"
exit 1
fi

function native_install_plugin() {
plugin=$1
msg=`/usr/share/elasticsearch/bin/elasticsearch-plugin install -b $plugin`
Expand All @@ -36,12 +45,21 @@ function copy_install_plugin() {
echo "successfully installed plugin $plugin"
}

for plugin in $(ls $src_plugins_dir); do
# check if plugin has suffix .zip or .gz or .tar.gz
echo "installing plugin $plugin"
if [[ $plugin == *.zip || $plugin == *.gz || $plugin == *.tar.gz ]]; then
native_install_plugins $src_plugins_dir/$plugin
else
copy_install_plugin $src_plugins_dir/$plugin
fi
done
# Install version-specific plugins - simply install all plugins that exist for this version
echo "Installing plugins for Elasticsearch version $ELASTICSEARCH_VERSION"

# Check if version-specific plugin directory exists
if [ -d "$src_plugins_dir/$ELASTICSEARCH_VERSION" ]; then
echo "Found plugin directory for version $ELASTICSEARCH_VERSION"

# Install all plugin subdirectories that exist
for plugin_dir in "$src_plugins_dir/$ELASTICSEARCH_VERSION"/*/; do
if [ -d "$plugin_dir" ]; then
plugin_name=$(basename "$plugin_dir")
echo "Installing $plugin_name plugin for version $ELASTICSEARCH_VERSION"
copy_install_plugin "$plugin_dir"
fi
done
else
echo "No plugin directory found for version $ELASTICSEARCH_VERSION"
fi
Loading