Commit 1628ce58 authored by Darko Poljak's avatar Darko Poljak

Replace rm with faster rsync --delete with empty src dir

parent 10dcf076
......@@ -160,16 +160,28 @@ delete_from_file()
file="$1"; shift
suffix="" # It will be set, if deleting incomplete backups.
[ $# -eq 1 ] && suffix="$1" && shift
# dirs for deletion will be moved to this trash dir inside destination dir
# - for fast mv operation
trash="$(mktemp -d "trash.XXXXXX")"
while read to_remove; do
mv "${to_remove}" "${trash}" ||
_exit_err "Moving ${to_remove} to ${trash} failed."
set -- "$@" "${to_remove}"
if [ "${suffix}" ]; then
to_remove_no_suffix="$(echo ${to_remove} | sed "s/$suffix\$//")"
mv "${to_remove_no_suffix}" "${trash}" ||
_exit_err "Moving ${to_remove_no_suffix} to ${trash} failed."
set -- "$@" "${to_remove_no_suffix}"
fi
done < "${file}"
_techo "Removing $@ ..."
[ "${VVERBOSE}" ] && echo rm "$@"
rm -rf "$@" || _exit_err "Removing $@ failed."
_techo "Removing $@ in ${trash}..."
empty_dir="empty-dir"
mkdir "${empty_dir}" || _exit_err "Empty directory ${empty_dir} cannot be created."
[ "${VVERBOSE}" ] && echo "rsync -a --delete ${empty_dir} ${trash}"
# rsync needs ending slash for directory content
rsync -a --delete "${empty_dir}/" "${trash}/" || _exit_err "Removing $@ failed."
rmdir "${trash}" || _exit_err "Removing ${trash} directory failed"
rmdir "${empty_dir}" || _exit_err "Removing ${empty_dir} directory failed"
}
display_version()
......
* Performance: replace rm -rf with faster rsync --delete empty src dir
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