skip mtree if disabled or missing

This commit is contained in:
Jérémy Lecour 2023-01-13 13:30:57 +01:00 committed by Jérémy Lecour
parent e9cf39ad40
commit 46c012f5fc

View file

@ -43,6 +43,8 @@ LOCAL_BACKUP_DIR="/home/backup"
: "${LOCAL_TASKS:=1}" : "${LOCAL_TASKS:=1}"
# Enable/disable sync tasks (default: enabled) # Enable/disable sync tasks (default: enabled)
: "${SYNC_TASKS:=1}" : "${SYNC_TASKS:=1}"
# Enable/disable mtree (default: enabled)
: "${MTREE_ENABLED:=1}"
# Source paths can be customized # Source paths can be customized
# Empty lines, and lines containing # or ; are ignored # Empty lines, and lines containing # or ; are ignored
@ -846,32 +848,41 @@ sync_tasks() {
echo "${RSYNC_INCLUDES}" | sed -e 's/\s*\(#\|;\).*//; /^\s*$/d' > "${rsync_includes_file}" echo "${RSYNC_INCLUDES}" | sed -e 's/\s*\(#\|;\).*//; /^\s*$/d' > "${rsync_includes_file}"
echo "${RSYNC_EXCLUDES}" | sed -e 's/\s*\(#\|;\).*//; /^\s*$/d' > "${rsync_excludes_file}" echo "${RSYNC_EXCLUDES}" | sed -e 's/\s*\(#\|;\).*//; /^\s*$/d' > "${rsync_excludes_file}"
# Dump filesystem stats with mtree if [ "${MTREE_ENABLED}" = "1" ]; then
log "SYNC_TASKS - start mtree" mtree_bin=$(command -v mtree)
declare -a mtree_files=() if [ -n "${mtree_bin}" ]; then
# Dump filesystem stats with mtree
log "SYNC_TASKS - start mtree"
# Loop over Rsync includes declare -a mtree_files=()
while read -r line ; do
# … but exclude for mtree what will be excluded by Rsync
mtree_excludes_file="$(mktemp --tmpdir "${PROGNAME}.mtree-excludes.XXXXXX")"
temp_files+=("${mtree_excludes_file}")
grep -E "^([^/]|${line})" "${rsync_excludes_file}" | sed -e "s|^${line}|.|" > "${mtree_excludes_file}"
mtree_file="/var/log/evobackup.$(basename "${line}").mtree" # Loop over Rsync includes
temp_files+=("${mtree_file}") while read -r line ; do
# … but exclude for mtree what will be excluded by Rsync
mtree_excludes_file="$(mktemp --tmpdir "${PROGNAME}.mtree-excludes.XXXXXX")"
temp_files+=("${mtree_excludes_file}")
grep -E "^([^/]|${line})" "${rsync_excludes_file}" | sed -e "s|^${line}|.|" > "${mtree_excludes_file}"
mtree -x -c -p "${line}" -X "${mtree_excludes_file}" > "${mtree_file}" mtree_file="/var/log/evobackup.$(basename "${line}").mtree"
mtree_files+=("${mtree_file}") temp_files+=("${mtree_file}")
done < "${rsync_includes_file}"
if [ "${#mtree_files[@]}" -le 0 ]; then ${mtree_bin} -x -c -p "${line}" -X "${mtree_excludes_file}" > "${mtree_file}"
error "ERROR: mtree didn't produce any file" mtree_files+=("${mtree_file}")
done < "${rsync_includes_file}"
if [ "${#mtree_files[@]}" -le 0 ]; then
error "ERROR: mtree didn't produce any file"
fi
log "SYNC_TASKS - stop mtree (files: ${mtree_files[*]})"
else
log "SYNC_TASKS - skip mtree (missing)"
fi
else
log "SYNC_TASKS - skip mtree (disabled)"
fi fi
log "SYNC_TASKS - stop mtree (files: ${mtree_files[*]})"
rsync_bin=$(command -v rsync) rsync_bin=$(command -v rsync)
# Build the final Rsync command # Build the final Rsync command