From 86ef4f31d39db8cdd1620d3a533f9fffd2c2b651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 7 Jan 2020 16:10:29 +0100 Subject: [PATCH] Check if the archive already exist and exit --- xymon/tar.client.logfiles.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xymon/tar.client.logfiles.sh b/xymon/tar.client.logfiles.sh index a0f30a7..6a46841 100755 --- a/xymon/tar.client.logfiles.sh +++ b/xymon/tar.client.logfiles.sh @@ -37,7 +37,13 @@ tar_file_name="${date_year}.${current_dir}${xz_compression_lvl}.tar.xz" # }}} -[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "Create an archive for ${current_dir} files between ${date_start} and ${date_end} using XZ's compression level : ${xz_compression_lvl}." +# If archive already exists +if [ -s "${tar_file_name}" ]; then + printf "${c_redb}%-6b${c_reset}\n" "${tar_file_name} already exists. Please manage this directory manually or remove the archive and restart." + exit 1 +else + [ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "Create an archive for ${current_dir} files between ${date_start} and ${date_end} using XZ's compression level : ${xz_compression_lvl}." +fi ## Get the list of files between the 2 dates and ignore tar files find . -type f -newermt "${date_start}" -not -newermt "${date_end}" -not -iname "*.tar*" -print0 | tar cJf "${tar_file_name}" --null -T -