From 620c5757b396711bdb6b984a385731854e512441 Mon Sep 17 00:00:00 2001 From: Oleg Sheynin Date: Mon, 22 Jun 2026 18:13:58 +0000 Subject: [PATCH] hostname to archive --- archive_logs.sh | 15 +++++++-------- cron.examples/crontab.txt | 8 ++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 cron.examples/crontab.txt diff --git a/archive_logs.sh b/archive_logs.sh index 5831ecd..35a388c 100755 --- a/archive_logs.sh +++ b/archive_logs.sh @@ -78,6 +78,13 @@ if [ "$files" == "" ] then echo "No files found older than ${Oldest} in ${LogDir}" else + oldest_file=$(ls -t ${files} | tail -1) + youngest_file=$(ls -tr ${files} | tail -1) + + tstmp1=$(stat --printf '%y' ${oldest_file}) + tstmp2=$(stat --printf '%y' ${youngest_file}) + tmsig="$(date -d "${tstmp1}" +"%Y%m%d_%H%M%S")-$(date -d "${tstmp2}" +"%Y%m%d_%H%M%S")" + TarFile="${LogArchiveDir}/${tmsig}.logs.tgz" if [ "${AddHostname}" == "Y" ] ; then TarFile="${LogArchiveDir}/${tmsig}.$(hostname -s).logs.tgz" @@ -86,14 +93,6 @@ else echo ----------------- echo ${files} - oldest_file=$(ls -t ${files} | tail -1) - youngest_file=$(ls -tr ${files} | tail -1) - - tstmp1=$(stat --printf '%y' ${oldest_file}) - tstmp2=$(stat --printf '%y' ${youngest_file}) - tmsig="$(date -d "${tstmp1}" +"%Y%m%d_%H%M%S")-$(date -d "${tstmp2}" +"%Y%m%d_%H%M%S")" - echo $tmsig - Cmd="tar zcvf ${TarFile} ${files}" echo $Cmd eval $Cmd diff --git a/cron.examples/crontab.txt b/cron.examples/crontab.txt new file mode 100644 index 0000000..42c64e3 --- /dev/null +++ b/cron.examples/crontab.txt @@ -0,0 +1,8 @@ +# +# ---------- pruning md_archive +10 3 * * * /works/utils/prune_data.sh -d /works/cvtt/md_archive -D '6 months ago' 2>&1 | /usr/bin/ts '[\%Y-\%m-\%d \%H:\%M:\%S]' >> /works/logs/$(date '+\%Y\%m\%d').prune_md_archive.log +# +# ---------- U t i l s +15 0 * * * /works/utils/archive_logs.sh -L /works/logs -A /works/archive/logs -D 'week ago' -H 2>&1 | /usr/bin/ts '[\%Y-\%m-\%d \%H:\%M:\%S]' >> /works/logs/$(date +\%Y\%m\%d).archive_logs.log +# +