Files
ad_trident/archiveLogs.sh

28 lines
687 B
Bash

#!/bin/sh
# Archive log files from the logs directory into a timestamped subdirectory, then delete them.
# Add to dockerStart.sh to run this script at startup, after the configuration setup:
# sh $CONF/archiveLogs.sh
LOGS_DIR=/conf/logs
ARCHIVE_DIR=$LOGS_DIR/archive
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
DEST=$ARCHIVE_DIR/$TIMESTAMP
# Find log files directly in the logs directory (non-recursive, skip archive subdir)
LOG_FILES=$(find "$LOGS_DIR" -maxdepth 1 -type f -name "*.log*")
if [ -z "$LOG_FILES" ]; then
echo "[archiveLogs] No log files to archive."
exit 0
fi
mkdir -p "$DEST"
for f in $LOG_FILES; do
mv "$f" "$DEST/"
done
echo "[archiveLogs] Archived logs to $DEST"