version finale

This commit is contained in:
2023-06-02 15:39:37 +00:00
parent 8c42d0bc0c
commit 6afdac8836

View File

@@ -2,36 +2,40 @@
set -eu set -eu
if [ "$#" -ne 1 ] ; then if [ "$#" -lt 1 ] ; then
echo "Usage: $O dir_to_backup" echo "Usage: $O dir_to_backup"
exit 1 exit 1
fi fi
test -d "$1" || { basedir=/var/backups
echo "$1 don't exist or not a dir" dest=${basedir}/$(date -I)
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)
mkdir -p "${dest}" || exit 3 mkdir -p "${dest}" || exit 3
# tar cpzf /var/backups/$(date -I)/etc.tgz /etc error=0
tar cpzf "${dest}/${src}.tgz" "${src}"
ret=$?
if [ $ret -eq 0 ] ; then for dir in "$@" ; do
find "${dest}" -maxdepth 1 -type f -mtime +7 -exec echo rm {} \; 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 fi
src=${dir}
# tar cpzf /var/backups/$(date -I)/etc.tgz /etc
tar cpzf "${dest}/${src}.tgz" "${src}"
((error+=$?))
done
if [ $error -eq 0 ] ; then
exit $ret find "${basedir}" -maxdepth 1 -type f -mtime +7 -exec echo rm {} \;
fi
exit $error