Skip to content

Commit dba4130

Browse files
committed
move check to script in docker
1 parent c7868d4 commit dba4130

1 file changed

Lines changed: 48 additions & 22 deletions

File tree

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

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,45 @@ jobs:
271271
REQUIRED_FILE_COUNT=2
272272
STABLE_AGE_SECONDS=5
273273
274-
# Helper script to count files not modified in the last N seconds
275-
# This runs inside the container
276-
COUNT_STABLE_FILES='
277-
STABLE_AGE='"${STABLE_AGE_SECONDS}"'
278-
NOW=$(date +%s)
279-
COUNT=0
280-
find '"${{ env.OUTPUT_DIR }}"' \( -name "*.tar" -o -name "*.tar.gz" -o -name "*.tgz" -o -name "*.tar.zst" \) -type f 2>/dev/null | while read -r f; do
281-
MTIME=$(stat -c %Y "$f" 2>/dev/null || echo "0")
282-
AGE=$((NOW - MTIME))
283-
if [ "$AGE" -ge "$STABLE_AGE" ]; then
284-
COUNT=$((COUNT + 1))
285-
fi
286-
echo "$COUNT"
287-
done | tail -1
288-
'
274+
# Create the helper script inside the container for reliable execution
275+
docker exec --user splunk splunk bash -c 'cat > /tmp/count_stable_files.sh << '\''SCRIPT'\''
276+
#!/bin/bash
277+
OUTPUT_DIR="$1"
278+
STABLE_AGE="$2"
279+
NOW=$(date +%s)
280+
TOTAL=0
281+
STABLE=0
282+
283+
while IFS= read -r f; do
284+
[ -z "$f" ] && continue
285+
TOTAL=$((TOTAL + 1))
286+
MTIME=$(stat -c %Y "$f" 2>/dev/null || echo "0")
287+
AGE=$((NOW - MTIME))
288+
if [ "$AGE" -ge "$STABLE_AGE" ]; then
289+
STABLE=$((STABLE + 1))
290+
fi
291+
done < <(find "$OUTPUT_DIR" -type f \( -name "*.tar" -o -name "*.tar.gz" -o -name "*.tgz" -o -name "*.tar.zst" \) 2>/dev/null)
292+
293+
echo "${TOTAL} ${STABLE}"
294+
SCRIPT'
295+
296+
docker exec --user splunk splunk chmod +x /tmp/count_stable_files.sh
297+
298+
# # Helper script to count files not modified in the last N seconds
299+
# # This runs inside the container
300+
# COUNT_STABLE_FILES='
301+
# STABLE_AGE='"${STABLE_AGE_SECONDS}"'
302+
# NOW=$(date +%s)
303+
# COUNT=0
304+
# find '"${{ env.OUTPUT_DIR }}"' \( -name "*.tar" -o -name "*.tar.gz" -o -name "*.tgz" -o -name "*.tar.zst" \) -type f 2>/dev/null | while read -r f; do
305+
# MTIME=$(stat -c %Y "$f" 2>/dev/null || echo "0")
306+
# AGE=$((NOW - MTIME))
307+
# if [ "$AGE" -ge "$STABLE_AGE" ]; then
308+
# COUNT=$((COUNT + 1))
309+
# fi
310+
# echo "$COUNT"
311+
# done | tail -1
312+
# '
289313

290314

291315
while [ $ELAPSED -lt $TOTAL_WAIT ]; do
@@ -294,16 +318,18 @@ jobs:
294318
docker exec --user splunk splunk ls /opt/splunk/var
295319
docker exec --user splunk splunk ls -l /opt/splunk/var/backups
296320

297-
# Total files (including still being written)
298-
TOTAL_COUNT=$(docker exec --user splunk splunk bash -c \
299-
"find ${{ env.OUTPUT_DIR }} \( -name '*.tar' -o -name '*.tar.gz' -o -name '*.tgz' -o -name '*.tar.zst' \) -type f 2>/dev/null | wc -l" \
300-
|| echo "0")
321+
# Get total and stable counts
322+
COUNTS=$(docker exec --user splunk splunk bash /tmp/count_stable_files.sh \
323+
"${{ env.OUTPUT_DIR }}" "$STABLE_AGE_SECONDS" 2>/dev/null || echo "0 0")
301324

302-
# Stable files (not modified for at least STABLE_AGE_SECONDS)
303-
STABLE_COUNT=$(docker exec --user splunk splunk bash -c "$COUNT_STABLE_FILES" || echo "0")
304-
# Handle empty result
325+
TOTAL_COUNT=$(echo "$COUNTS" | awk '{print $1}')
326+
STABLE_COUNT=$(echo "$COUNTS" | awk '{print $2}')
327+
328+
# Handle empty results
329+
TOTAL_COUNT=${TOTAL_COUNT:-0}
305330
STABLE_COUNT=${STABLE_COUNT:-0}
306331

332+
307333
echo " [${ELAPSED}s/${TOTAL_WAIT}s] Total files: ${TOTAL_COUNT} | Stable (>${STABLE_AGE_SECONDS}s): ${STABLE_COUNT}"
308334

309335
if [ "$STABLE_COUNT" -ge $REQUIRED_FILE_COUNT ]; then

0 commit comments

Comments
 (0)