Commit 61ab45fc authored by Darko Poljak's avatar Darko Poljak

Fix excluding destination dir from removal

Touch can lead to wrong ls order, and destination dir gets selected for
removal.
Use grep -v to exclude, instead of touch.
parent 6c24e8a7
......@@ -767,20 +767,27 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
_techo "Using ${oldest_bak} for destination dir ${destination_dir}"
if mv "${oldest_bak}" "${destination_dir}"; then
# Touch dest dir so it is not sorted wrong in listings below.
touch "${destination_dir}"
ls_rm_exclude=$(basename "${destination_dir}")
# We have something to remove only if count > interval.
remove="$((count - c_interval))"
else
_techo_err "Renaming oldest backup ${oldest_bak} to ${destination_dir} failed, removing it."
remove="$((count - c_interval + 1))"
ls_rm_exclude=""
fi
if [ "${remove}" -gt 0 ]; then
_techo "Removing ${remove} backup(s)..."
# shellcheck disable=SC2010
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
if [ -z "${ls_rm_exclude}" ]; then
# shellcheck disable=SC2010
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
else
# shellcheck disable=SC2010
ls -${TSORT}1r | grep -v "${ls_rm_exclude}" | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
fi
delete_from_file "${TMP}" &
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment