From 6afdac8836450a0658e9160daf2cd3897271aaf5 Mon Sep 17 00:00:00 2001 From: Thomas C Date: Fri, 2 Jun 2023 15:39:37 +0000 Subject: [PATCH] version finale --- script.sh | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/script.sh b/script.sh index 622f7da..2703e76 100644 --- a/script.sh +++ b/script.sh @@ -2,36 +2,40 @@ set -eu -if [ "$#" -ne 1 ] ; then +if [ "$#" -lt 1 ] ; then echo "Usage: $O dir_to_backup" exit 1 fi -test -d "$1" || { - echo "$1 don't exist or not a dir" - exit 2 -} - -if [ ! -d "$1" ] ; then - echo "$1 don't exist or not a dir" - exit 2 -fi - -src=$1 -dest=/var/backups/$(date -I) +basedir=/var/backups +dest=${basedir}/$(date -I) mkdir -p "${dest}" || exit 3 +error=0 + +for dir in "$@" ; do + test -d "${dir}" || { + echo "${dir} don't exist or not a dir" + ((error+=1)) + continue + } + + if [ ! -d "${dir}" ] ; then + echo "${dir} don't exist or not a dir" + ((error+=1)) + continue + fi + + src=${dir} + # tar cpzf /var/backups/$(date -I)/etc.tgz /etc -tar cpzf "${dest}/${src}.tgz" "${src}" -ret=$? + tar cpzf "${dest}/${src}.tgz" "${src}" + ((error+=$?)) -if [ $ret -eq 0 ] ; then - find "${dest}" -maxdepth 1 -type f -mtime +7 -exec echo rm {} \; +done + +if [ $error -eq 0 ] ; then + find "${basedir}" -maxdepth 1 -type f -mtime +7 -exec echo rm {} \; fi - - - - - -exit $ret \ No newline at end of file +exit $error \ No newline at end of file