From f8c50c6e6356a6989fc630b9ac7d2c7b66cf51a9 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 20 Apr 2026 22:43:52 +0200 Subject: [PATCH] add script to archive log files into timestamped subdirectory --- archiveLogs.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 archiveLogs.sh diff --git a/archiveLogs.sh b/archiveLogs.sh new file mode 100644 index 0000000..b8c6483 --- /dev/null +++ b/archiveLogs.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Archive log files from the logs directory into a timestamped subdirectory, then delete them. + +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"