#------------------------------------------------------------------------------
TAR() {
- local cmd="tar --create --gzip --file $* >/dev/null 2>&1 || true"
+ local cmd="tar --create --gzip"
if [[ "${VERBOSE}" == "y" ]] ; then
- cmd="tar --create --gzip --verbose --file $* 2>&1 | tee -a \"${LOGFILE}\" || true"
+ cmd+=" --verbose"
+ fi
+ cmd+=" --file $1"
+ shift
+ while [[ "$#" -gt 0 ]] ; do
+ cmd+=" \"$1\""
+ shift
+ done
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" 2>&1 | tee -a \"${LOGFILE}\" || true"
+ else
+ cmd+=" >/dev/null 2>&1 || true"
fi
+
if [[ "${SIMULATE}" == "y" ]] ; then
info "Executing: ${cmd}"
return
local bdir="${1}"
local tarball_base="${2}"
- local tarball="${BACKUP_DIR}/${tarball_base}.tar.gz"
+ local split_dir="n"
+ if [[ "$#" -ge 3 ]] ; then
+ split_dir="$3"
+ fi
+ empty_line
+ debug "Splitting dirs of '${CYAN}/${bdir}${NORMAL}' on dir_backup(): '${CYAN}${split_dir}${NORMAL}'."
+
+ local tarball=
- info "Backup of '${CYAN}/${bdir}${NORMAL}' => '${CYAN}${tarball}${NORMAL}'."
- TAR "${tarball}" "${bdir}"
+ if [[ "${split_dir}" != "y" ]] ; then
+ tarball="${BACKUP_DIR}/${tarball_base}.tar.gz"
+ info "Backup of '${CYAN}/${bdir}${NORMAL}' => '${CYAN}${tarball}${NORMAL}'."
+ TAR "${tarball}" "${bdir}"
+ return
+ fi
+
+ local -a non_dirs=()
+ local path=
+ local bname=
+ oifs="${IFS}"
+ IFS="
+"
+
+ for bname in $( ls -1 -A "${bdir}" ) ; do
+ path="${bdir}/${bname}"
+ empty_line
+ debug "Checking path '${CYAN}${path}${NORMAL}' ..."
+ if [[ -d "${path}" ]] ; then
+ tarball="${BACKUP_DIR}/${tarball_base}-${bname}.tar.gz"
+ info "Backup of '${CYAN}${path}${NORMAL}' => '${CYAN}${tarball}${NORMAL}'."
+ TAR "${tarball}" "${path}"
+ continue
+ fi
+ non_dirs+=( "${path}" )
+ done
+
+ IFS="${oifs}"
+
+ if [[ "${#non_dirs[*]}" -ge "1" ]] ; then
+ tarball="${BACKUP_DIR}/${tarball_base}.non_dirs.tar.gz"
+ empty_line
+ info "Backup of non directory paths below '${CYAN}/${bdir}${NORMAL}' => '${CYAN}${tarball}${NORMAL}'."
+ TAR "${tarball}" "${non_dirs[@]}"
+ fi
}
if [[ -d "var/bind" ]] ; then
dir_backup "var/bind" "var-bind"
fi
- dir_backup "var/lib" "var-lib"
+ dir_backup "var/lib" "var-lib" "y"
dir_backup "var/log" "var-log"
dir_backup "var/spool/cron" "var-spool-cron"
if [[ -d "var/spool/postfix" ]] ; then