extend delete_from_file() to allow removal of suffix files

Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
This commit is contained in:
Nico Schottelius 2009-10-30 19:25:23 +01:00
parent 3d92f30574
commit 4865f3c8c6

View file

@ -100,16 +100,22 @@ pcmd()
fi fi
} }
delete_from_file()
{
# #
# ssh-"feature": we cannot do '... read ...; ssh ...; < file', # ssh-"feature": we cannot do '... read ...; ssh ...; < file',
# because ssh reads stdin! -n does not work -> does not ask for password # because ssh reads stdin! -n does not work -> does not ask for password
# Allow deletion for files with suffix and without suffix
# #
delete_from_file()
{
file="$1"; shift file="$1"; shift
while read to_remove; do set -- "$@" "${ddir}/${to_remove}"; done < "${file}" suffix="$1" # only set for delete_incomplete
# [ "$#" = 1 ] && suffix="$1" && shift
while read to_remove; do
set -- "$@" "${ddir}/${to_remove}"
[ "$suffix" ] && set -- "$@" "$(echo ${to_remove} | sed "s/$suffix\$//")"
done < "${file}"
_techo "Removing $@ ..." _techo "Removing $@ ..."
pcmd rm ${VVERBOSE} -rf "$@" || _exit_err "Removing $@ failed." pcmd echo rm ${VVERBOSE} -rf "$@" || _exit_err "Removing $@ failed."
} }
display_version() display_version()
@ -425,14 +431,29 @@ while [ "${i}" -lt "${no_sources}" ]; do
# #
# Check: incomplete backups? (needs echo to remove newlines) # Check: incomplete backups? (needs echo to remove newlines)
# #
# *.marker: not possible, creates an error, if no *.marker exists
# -> catch return value
pcmd ls -1 "${ddir}/"*"${CMARKER}" > "${TMP}" 2>/dev/null; ret=$?
if [ "$ret" -eq 0 ]; then
_techo "Incomplete backups: ${incomplete}"
if [ -f "${c_delete_incomplete}" ]; then
delete_from_file "${TMP}"
fi
fi
incomplete="$(echo \ incomplete="$(echo \
$(pcmd ls -1 "${ddir}/" | \ $(pcmd ls -1 "${ddir}/" | \
awk '/ENVIRON["CMARKER"]$/ { awk '
BEGIN { regexp=ENVIRON["CMARKER"] "$" }
$0 ~ regexp {
print $0; print $0;
gsub(ENVIRON["CMARKER"]$,"",$0); gsub(ENVIRON["CMARKER"]$,"",$0);
print $0 print $0
}' | \ }' | tee "${TMP}"))"
tee "${TMP}"))"
FIXME: stopped here! -> gsub broken
if [ "${incomplete}" ]; then if [ "${incomplete}" ]; then
_techo "Incomplete backups: ${incomplete}" _techo "Incomplete backups: ${incomplete}"