From b940727fb4981d5f257997690b61b58bf2076e34 Mon Sep 17 00:00:00 2001 From: bigrosss Date: Sat, 27 Dec 2025 21:38:06 +0100 Subject: [PATCH] feat(bin): add log archive helper Adds a script to compress all log files into a timestamped tarball and then remove the originals, helping manage disk usage. --- bin/archive_logs.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bin/archive_logs.sh diff --git a/bin/archive_logs.sh b/bin/archive_logs.sh new file mode 100644 index 00000000..11bc9544 --- /dev/null +++ b/bin/archive_logs.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Compresses all log files into a tar.gz archive with a timestamp and clears the original files. +# +# Usage: +# ./bin/archive_logs.sh +# +# Archived files are stored in ./archives/ with a filename like logs-YYYYMMDDHHMM.tar.gz + +LOG_DIR="./logs" +ARCHIVE_DIR="./archives" +TIMESTAMP=$(date +"%Y%m%d%H%M") + +mkdir -p "${ARCHIVE_DIR}" + +ARCHIVE_NAME="${ARCHIVE_DIR}/logs-${TIMESTAMP}.tar.gz" +tar -czf "${ARCHIVE_NAME}" -C "${LOG_DIR}" . +echo "Logs archived to ${ARCHIVE_NAME}" + +# Remove original logs +find "${LOG_DIR}" -type f -name "*.log" -delete +echo "Original log files removed."