#! /bin/bash set -eu if [ "$#" -lt 1 ] ; then echo "Usage: $O dir_to_backup" exit 1 fi 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}" ((error+=$?)) done if [ $error -eq 0 ] ; then find "${basedir}" -maxdepth 1 -type f -mtime +7 -exec echo rm {} \; fi exit $error