Skip to content

Commit 81d738d

Browse files
committed
change remote extract script
1 parent 444f56b commit 81d738d

1 file changed

Lines changed: 26 additions & 34 deletions

File tree

.github/workflows/splunkconf-backup-test.yml

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,26 +1089,29 @@ jobs:
10891089
}
10901090
10911091
# ------------------------------------------------------------
1092-
# Helper: choose tar decompression flag based on extension
1092+
# Helper: extract an archive inside the container at SPLUNK_HOME
1093+
# Uses explicit case logic (no dynamic command strings).
10931094
# ------------------------------------------------------------
1094-
tar_extract_cmd() {
1095-
local archive="$1"
1096-
local target="$2"
1097-
case "$archive" in`
1095+
extract_in_container() {
1096+
local archive_in_container="$1" # full path inside the container
1097+
local target_dir="$2" # extraction target inside container
1098+
1099+
case "$archive_in_container" in
10981100
*.tar.zst)
1099-
# zstd must be available inside the container.
1100-
# Splunk Enterprise images typically have it; fallback otherwise.
1101-
echo "tar -I zstd -xf '${archive}' -C '${target}'"
1101+
docker exec --user root splunk bash -c \
1102+
"tar --zstd -xf '$archive_in_container' -C '$target_dir'"
11021103
;;
11031104
*.tar.gz|*.tgz)
1104-
echo "tar -xzf '${archive}' -C '${target}'"
1105+
docker exec --user root splunk bash -c \
1106+
"tar -xzf '$archive_in_container' -C '$target_dir'"
11051107
;;
11061108
*.tar)
1107-
echo "tar -xf '${archive}' -C '${target}'"
1109+
docker exec --user root splunk bash -c \
1110+
"tar -xf '$archive_in_container' -C '$target_dir'"
11081111
;;
11091112
*)
1110-
# Best-effort auto-detect
1111-
echo "tar -xf '${archive}' -C '${target}' 2>/dev/null || tar -xzf '${archive}' -C '${target}' 2>/dev/null || tar -I zstd -xf '${archive}' -C '${target}'"
1113+
echo "Unknown archive format: $archive_in_container"
1114+
return 1
11121115
;;
11131116
esac
11141117
}
@@ -1132,30 +1135,19 @@ jobs:
11321135
echo " ⚠️ ¦ Restoring ${label} backup: ${fname}"
11331136
echo " Source: ${local_path}"
11341137
echo " Target: ${SPLUNK_HOME}/ (inside container)"
1135-
1136-
# Make sure SPLUNK_HOME exists in the container (it does for normal images,
1137-
# but safe-guard in case of unusual layouts)
1138-
docker exec --user root splunk bash -c "mkdir -p '${SPLUNK_HOME}'"
1139-
1140-
# Copy archive to /tmp inside the container
1138+
1139+
docker exec --user root splunk mkdir -p "${SPLUNK_HOME}"
11411140
docker cp "${local_path}" "splunk:/tmp/${fname}"
11421141
1143-
# Build and execute the appropriate extract command (as splunk so we dont have to fix permissions
1144-
local extract_cmd
1145-
extract_cmd=$(tar_extract_cmd "/tmp/${fname}" "${SPLUNK_HOME}")
1146-
echo " Extract: ${extract_cmd}"
1147-
1148-
docker exec --user splunk splunk bash -c "${extract_cmd}"
1149-
local rc=$?
1150-
if [ $rc -ne 0 ]; then
1151-
echo " 💥 Extraction failed for ${label} (rc=${rc})"
1142+
if extract_in_container "/tmp/${fname}" "${SPLUNK_HOME}"; then
1143+
echo " ✅ OK: ${label} backup extracted successfully."
1144+
else
1145+
echo " ❌ ERROR: Extraction failed for ${label}"
1146+
docker exec --user root splunk rm -f "/tmp/${fname}" || true
11521147
return 1
11531148
fi
11541149
1155-
# Cleanup tmp file
1156-
docker exec --user root splunk bash -c "rm -f '/tmp/${fname}'"
1157-
1158-
echo " ✅ ${label} backup extracted successfully."
1150+
docker exec --user root splunk rm -f "/tmp/${fname}" || true
11591151
return 0
11601152
}
11611153
@@ -1174,7 +1166,7 @@ jobs:
11741166
11751167
if [ -n "$LATEST_ETC" ]; then
11761168
restore_archive_to_splunk_home "$LATEST_ETC" "ETC" || {
1177-
echo "â ERROR: Failed to restore ETC backup"
1169+
echo " ERROR: Failed to restore ETC backup"
11781170
exit 1
11791171
}
11801172
else
@@ -1199,11 +1191,11 @@ jobs:
11991191
12001192
if [ -n "$LATEST_STATE" ]; then
12011193
restore_archive_to_splunk_home "$LATEST_STATE" "STATE" || {
1202-
echo "💥 ERROR: Failed to restore STATE backup"
1194+
echo " ERROR: Failed to restore STATE backup"
12031195
exit 1
12041196
}
12051197
else
1206-
echo "💥 ERROR: No STATE backup found in ./test_output/"
1198+
echo " ERROR: No STATE backup found in ./test_output/"
12071199
ls -la ./test_output/ || true
12081200
exit 1
12091201
fi

0 commit comments

Comments
 (0)