import new pcmd
This commit is contained in:
parent
09876ee932
commit
89b4c993a5
1 changed files with 49 additions and 13 deletions
62
ccollect.sh
62
ccollect.sh
|
@ -75,6 +75,15 @@ add_name()
|
||||||
sed "s:^:\[${name}\] :"
|
sed "s:^:\[${name}\] :"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pcmd()
|
||||||
|
{
|
||||||
|
if [ "$remote_server" ]; then
|
||||||
|
ssh "$host" "$@"
|
||||||
|
else
|
||||||
|
"$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Version
|
# Version
|
||||||
#
|
#
|
||||||
|
@ -273,6 +282,7 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
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_incomplete="${backup}/delete_incomplete"
|
c_incomplete="${backup}/delete_incomplete"
|
||||||
|
c_remote_host="${backup}/remote_host"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Marking backups: If we abort it's not removed => Backup is broken
|
# Marking backups: If we abort it's not removed => Backup is broken
|
||||||
|
@ -343,24 +353,47 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
if [ ! -f "${c_source}" ]; then
|
if [ ! -f "${c_source}" ]; then
|
||||||
_exit_err "Source description \"${c_source}\" is not a file. Skipping."
|
_exit_err "Source description \"${c_source}\" is not a file. Skipping."
|
||||||
else
|
else
|
||||||
source=$(cat "${c_source}"); ret=$?
|
source=$(cat "${c_source}"); ret="$?"
|
||||||
if [ ${ret} -ne 0 ]; then
|
if [ "${ret}" -ne 0 ]; then
|
||||||
_exit_err "Source ${c_source} is not readable. Skipping."
|
_exit_err "Source ${c_source} is not readable. Skipping."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# destination can be anything rsync supports
|
# Destination is a path
|
||||||
#
|
#
|
||||||
if [ ! -f "${c_dest}" ]; then
|
if [ ! -f "${c_dest}" ]; then
|
||||||
_exit_err "Destination ${c_dest} is not a file. Skipping."
|
_exit_err "Destination ${c_dest} is not a file. Skipping."
|
||||||
else
|
else
|
||||||
destination=$(cat "${c_dest}"); ret=$?
|
ddir=$(cat "${c_dest}"); ret="$?"
|
||||||
if [ "${ret}" -ne 0 ]; then
|
if [ "${ret}" -ne 0 ]; then
|
||||||
_exit_err "Destination ${c_dest} is not readable. Skipping."
|
_exit_err "Destination ${c_dest} is not readable. Skipping."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# do we backup to a remote host? then set pre-cmd
|
||||||
|
#
|
||||||
|
if [ -f "${c_remote_host}" ]; then
|
||||||
|
# adjust ls and co
|
||||||
|
remote_host=$(cat "${c_remote_host}"); ret="$?"
|
||||||
|
if [ "${ret}" -ne 0 ]; then
|
||||||
|
_exit_err "Remote host file ${c_remote_host} exists, but is not readable. Skipping."
|
||||||
|
fi
|
||||||
|
pcmd="ssh ${remote_host}"
|
||||||
|
destination="${remote_host}:${ddir}"
|
||||||
|
else
|
||||||
|
pcmd=""
|
||||||
|
destination="${ddir}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# check for existence / use real name
|
||||||
|
#
|
||||||
|
# FIXME: ssh / grouping
|
||||||
|
ddir=$($pcmd (cd "$ddir" || _exit_err "Cannot change to ${ddir}. Skipping."
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check whether to delete incomplete backups
|
# Check whether to delete incomplete backups
|
||||||
#
|
#
|
||||||
|
@ -415,14 +448,17 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
#
|
#
|
||||||
# Check for incomplete backups
|
# Check for incomplete backups
|
||||||
#
|
#
|
||||||
( cd "${c_dest}" 2>/dev/null && ls -1 "${INTERVAL}"*".${c_marker}" > "${TMP}" 2>/dev/null)
|
(
|
||||||
|
$pcmd cd "${ddir}" 2>/dev/null && \
|
||||||
|
$pcmd ls -1 "${INTERVAL}"*".${c_marker}" > "${TMP}" 2>/dev/null
|
||||||
|
)
|
||||||
|
|
||||||
while read incomplete; do
|
while read incomplete; do
|
||||||
realincomplete=$(echo ${incomplete} | sed "s/\\.${c_marker}\$//")
|
realincomplete=$(echo ${incomplete} | sed "s/\\.${c_marker}\$//")
|
||||||
_techo "Incomplete backup: ${realincomplete}"
|
_techo "Incomplete backup: ${realincomplete}"
|
||||||
if [ "${DELETE_INCOMPLETE}" = "yes" ]; then
|
if [ "${DELETE_INCOMPLETE}" = "yes" ]; then
|
||||||
_techo "Deleting ${realincomplete} ..."
|
_techo "Deleting ${realincomplete} ..."
|
||||||
rm $VVERBOSE -rf "${c_dest}/${realincomplete}" || \
|
$pcmd rm $VVERBOSE -rf "${ddir}/${realincomplete}" || \
|
||||||
_exit_err "Removing ${realincomplete} failed."
|
_exit_err "Removing ${realincomplete} failed."
|
||||||
fi
|
fi
|
||||||
done < "${TMP}"
|
done < "${TMP}"
|
||||||
|
@ -432,7 +468,7 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
# check if maximum number of backups is reached, if so remove
|
# check if maximum number of backups is reached, if so remove
|
||||||
# use grep and ls -p so we only look at directories
|
# use grep and ls -p so we only look at directories
|
||||||
#
|
#
|
||||||
count=$(cd "${c_dest}" && ls -p1 | grep "^${INTERVAL}\..*/\$" | wc -l \
|
count=$($pcmd cd "${ddir}" && $pcmd ls -p1 | grep "^${INTERVAL}\..*/\$" | wc -l \
|
||||||
| sed 's/^ *//g') || _exit_err "Counting backups failed"
|
| sed 's/^ *//g') || _exit_err "Counting backups failed"
|
||||||
|
|
||||||
_techo "Existing backups: ${count} Total keeping backups: ${c_interval}"
|
_techo "Existing backups: ${count} Total keeping backups: ${c_interval}"
|
||||||
|
@ -442,12 +478,12 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
remove=$((${count} - ${substract}))
|
remove=$((${count} - ${substract}))
|
||||||
_techo "Removing ${remove} backup(s)..."
|
_techo "Removing ${remove} backup(s)..."
|
||||||
|
|
||||||
( cd "${c_dest}" 2>/dev/null && ls -p1 | grep "^${INTERVAL}\..*/\$" | \
|
( $pcmd cd "${ddir}" 2>/dev/null && $pcmd ls -p1 | grep "^${INTERVAL}\..*/\$" | \
|
||||||
sort -n | head -n "${remove}" ) > "${TMP}"
|
sort -n | head -n "${remove}" ) > "${TMP}"
|
||||||
|
|
||||||
while read to_remove; do
|
while read to_remove; do
|
||||||
_techo "Removing ${to_remove} ..."
|
_techo "Removing ${to_remove} ..."
|
||||||
rm ${VVERBOSE} -rf "${c_dest}/${to_remove}" || \
|
$pcmd rm ${VVERBOSE} -rf "${ddir}/${to_remove}" || \
|
||||||
_exit_err "Removing ${to_remove} failed."
|
_exit_err "Removing ${to_remove} failed."
|
||||||
done < "${TMP}"
|
done < "${TMP}"
|
||||||
fi
|
fi
|
||||||
|
@ -459,14 +495,14 @@ while [ "${i}" -lt "${no_sources}" ]; do
|
||||||
# Use ls -1c instead of -1t, because last modification maybe the same on all
|
# Use ls -1c instead of -1t, because last modification maybe the same on all
|
||||||
# and metadate update (-c) is updated by rsync locally.
|
# and metadate update (-c) is updated by rsync locally.
|
||||||
#
|
#
|
||||||
rel_last_dir="$(cd "${c_dest}" && ls -tcp1 | grep '/$' | head -n 1)" || \
|
rel_last_dir="$($pcmd cd "${ddir}" && $pcmd ls -tcp1 | grep '/$' | head -n 1)" || \
|
||||||
_exit_err "Failed to list contents of ${c_dest}."
|
_exit_err "Failed to list contents of ${ddir}."
|
||||||
last_dir="${c_dest}/${rel_last_dir}"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# clone from old backup, if existing
|
# clone from old backup, if existing
|
||||||
#
|
#
|
||||||
if [ "${last_dir}" ]; then
|
if [ "${rel_last_dir}" ]; then
|
||||||
|
last_dir="${ddir}/${rel_last_dir}"
|
||||||
# must be absolute, otherwise rsync uses it relative to
|
# must be absolute, otherwise rsync uses it relative to
|
||||||
# the destination directory. See rsync(1).
|
# the destination directory. See rsync(1).
|
||||||
abs_last_dir="$(cd "${last_dir}" && pwd -P)" || \
|
abs_last_dir="$(cd "${last_dir}" && pwd -P)" || \
|
||||||
|
|
Loading…
Reference in a new issue