Create function 'delete_from_file()'
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
This commit is contained in:
parent
e6a0300b9b
commit
4ba0dab260
1 changed files with 25 additions and 22 deletions
47
ccollect.sh
47
ccollect.sh
|
@ -98,6 +98,18 @@ pcmd()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_from_file()
|
||||||
|
{
|
||||||
|
#
|
||||||
|
# ssh-"feature": we cannot do '... read ...; ssh ...; < file',
|
||||||
|
# because ssh reads stdin! -n does not work -> does not ask for password
|
||||||
|
#
|
||||||
|
file="$1"; shift
|
||||||
|
while read to_remove; do set -- "$@" "${ddir}/${to_remove}"; done < "${file}"
|
||||||
|
_techo "Removing $@ ..."
|
||||||
|
pcmd rm ${VVERBOSE} -rf "$@" || _exit_err "Removing $@ failed."
|
||||||
|
}
|
||||||
|
|
||||||
display_version()
|
display_version()
|
||||||
{
|
{
|
||||||
echo "${FULL_VERSION}"
|
echo "${FULL_VERSION}"
|
||||||
|
@ -283,7 +295,7 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
c_dest="${backup}/destination"
|
c_dest="${backup}/destination"
|
||||||
c_pre_exec="${backup}/pre_exec"
|
c_pre_exec="${backup}/pre_exec"
|
||||||
c_post_exec="${backup}/post_exec"
|
c_post_exec="${backup}/post_exec"
|
||||||
c_marker=".ccollect-marker"
|
c_marker="ccollect-marker"
|
||||||
for opt in exclude verbose very_verbose rsync_options summary delete_incomplete \
|
for opt in exclude verbose very_verbose rsync_options summary delete_incomplete \
|
||||||
remote_host rsync_failure_codes mtime quiet_if_down ; do
|
remote_host rsync_failure_codes mtime quiet_if_down ; do
|
||||||
if [ -f "${backup}/${opt}" -o -f "${backup}/no_${opt}" ]; then
|
if [ -f "${backup}/${opt}" -o -f "${backup}/no_${opt}" ]; then
|
||||||
|
@ -414,19 +426,19 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
( pcmd cd "${ddir}" ) || _exit_err "Cannot change to ${ddir}. Skipping."
|
( pcmd cd "${ddir}" ) || _exit_err "Cannot change to ${ddir}. Skipping."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check: incomplete backups?
|
# Check: incomplete backups? (needs echo to remove newlines)
|
||||||
#
|
#
|
||||||
pcmd ls -1 "${ddir}/"*".${c_marker}" 2>/dev/null | while read marker; do
|
incomplete="$(echo \
|
||||||
incomplete="$(echo ${marker} | sed "s/\\.${c_marker}\$//")"
|
$(pcmd ls -1 "${ddir}/" | \
|
||||||
_techo "Incomplete backup: ${incomplete}"
|
awk "/\.${c_marker}\$/ { print \$0; gsub(\"\.${c_marker}\$\",\"\",\$0); print \$0 }" | \
|
||||||
|
tee "${TMP}"))"
|
||||||
|
|
||||||
|
if [ "${incomplete}" ]; then
|
||||||
|
_techo "Incomplete backups: ${incomplete}"
|
||||||
if [ -f "${c_delete_incomplete}" ]; then
|
if [ -f "${c_delete_incomplete}" ]; then
|
||||||
_techo "Deleting ${incomplete} ..."
|
delete_from_file "${TMP}"
|
||||||
pcmd rm $VVERBOSE -rf "${incomplete}" || \
|
|
||||||
_exit_err "Removing ${incomplete} failed."
|
|
||||||
pcmd rm $VVERBOSE -f "${marker}" || \
|
|
||||||
_exit_err "Removing ${marker} failed."
|
|
||||||
fi
|
fi
|
||||||
done
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Interval definition: First try source specific, fallback to default
|
# Interval definition: First try source specific, fallback to default
|
||||||
|
@ -459,16 +471,7 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
head -n "${remove}" > "${TMP}" || \
|
head -n "${remove}" > "${TMP}" || \
|
||||||
_exit_err "Listing old backups failed"
|
_exit_err "Listing old backups failed"
|
||||||
|
|
||||||
#
|
delete_from_file "${TMP}"
|
||||||
# ssh-"feature": we cannot do '... read ...; ssh ...; < file',
|
|
||||||
# because ssh reads stdin! -n does not work -> does not ask for password
|
|
||||||
#
|
|
||||||
(
|
|
||||||
set -- ""
|
|
||||||
while read to_remove; do set -- "$@" "${ddir}/${to_remove}"; done < "${TMP}"
|
|
||||||
_techo "Removing $@ ..."
|
|
||||||
pcmd rm ${VVERBOSE} -rf "$@"
|
|
||||||
) || _exit_err "Removing $@ failed."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -531,7 +534,7 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
#
|
#
|
||||||
if [ -z "$fail" ]; then
|
if [ -z "$fail" ]; then
|
||||||
pcmd rm "${destination_dir}.${c_marker}" || \
|
pcmd rm "${destination_dir}.${c_marker}" || \
|
||||||
_exit_err "Removing ${destination_dir}/${c_marker} failed."
|
_exit_err "Removing ${destination_dir}.${c_marker} failed."
|
||||||
if [ "${ret}" -ne 0 ]; then
|
if [ "${ret}" -ne 0 ]; then
|
||||||
_techo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)."
|
_techo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)."
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue