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
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
exit $error