Commit 49ee2a24 authored by Nico Schottelius's avatar Nico Schottelius

remote support seems to work, even tested it ;-)

parent 89b4c993
...@@ -77,8 +77,8 @@ add_name() ...@@ -77,8 +77,8 @@ add_name()
pcmd() pcmd()
{ {
if [ "$remote_server" ]; then if [ "$remote_host" ]; then
ssh "$host" "$@" ssh "$remote_host" "$@"
else else
"$@" "$@"
fi fi
...@@ -380,18 +380,17 @@ while [ "${i}" -lt "${no_sources}" ]; do ...@@ -380,18 +380,17 @@ while [ "${i}" -lt "${no_sources}" ]; do
if [ "${ret}" -ne 0 ]; then if [ "${ret}" -ne 0 ]; then
_exit_err "Remote host file ${c_remote_host} exists, but is not readable. Skipping." _exit_err "Remote host file ${c_remote_host} exists, but is not readable. Skipping."
fi fi
pcmd="ssh ${remote_host}"
destination="${remote_host}:${ddir}" destination="${remote_host}:${ddir}"
else else
pcmd="" remote_host=""
destination="${ddir}" destination="${ddir}"
fi fi
export remote_host
# #
# check for existence / use real name # check for existence / use real name
# #
# FIXME: ssh / grouping pcmd cd "$ddir" || _exit_err "Cannot change to ${ddir}. Skipping."
ddir=$($pcmd (cd "$ddir" || _exit_err "Cannot change to ${ddir}. Skipping."
# #
...@@ -448,27 +447,29 @@ while [ "${i}" -lt "${no_sources}" ]; do ...@@ -448,27 +447,29 @@ while [ "${i}" -lt "${no_sources}" ]; do
# #
# Check for incomplete backups # Check for incomplete backups
# #
( pcmd ls -1 "$ddir/${INTERVAL}"*".${c_marker}" > "${TMP}" 2>/dev/null
$pcmd cd "${ddir}" 2>/dev/null && \
$pcmd ls -1 "${INTERVAL}"*".${c_marker}" > "${TMP}" 2>/dev/null
)
i=0
while read incomplete; do while read incomplete; do
realincomplete=$(echo ${incomplete} | sed "s/\\.${c_marker}\$//") eva incomplete_$i=$(echo ${incomplete} | sed "s/\\.${c_marker}\$//")
i=$(($i+1))
done < "${TMP}"
while [ $i -gt 0 ]; do
eval realincomplete=\"incomplete_$i\"
_techo "Incomplete backup: ${realincomplete}" _techo "Incomplete backup: ${realincomplete}"
if [ "${DELETE_INCOMPLETE}" = "yes" ]; then if [ "${DELETE_INCOMPLETE}" = "yes" ]; then
_techo "Deleting ${realincomplete} ..." _techo "Deleting ${realincomplete} ..."
$pcmd rm $VVERBOSE -rf "${ddir}/${realincomplete}" || \ pcmd rm $VVERBOSE -rf "${ddir}/${realincomplete}" || \
_exit_err "Removing ${realincomplete} failed." _exit_err "Removing ${realincomplete} failed."
fi fi
done < "${TMP}" done
# #
# 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=$($pcmd cd "${ddir}" && $pcmd ls -p1 | grep "^${INTERVAL}\..*/\$" | wc -l \ count=$(pcmd ls -p1 "${ddir}" | 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}"
...@@ -478,14 +479,21 @@ while [ "${i}" -lt "${no_sources}" ]; do ...@@ -478,14 +479,21 @@ while [ "${i}" -lt "${no_sources}" ]; do
remove=$((${count} - ${substract})) remove=$((${count} - ${substract}))
_techo "Removing ${remove} backup(s)..." _techo "Removing ${remove} backup(s)..."
( $pcmd cd "${ddir}" 2>/dev/null && $pcmd ls -p1 | grep "^${INTERVAL}\..*/\$" | \ pcmd ls -p1 "$ddir" | grep "^${INTERVAL}\..*/\$" | \
sort -n | head -n "${remove}" ) > "${TMP}" sort -n | head -n "${remove}" > "${TMP}"
i=0
while read to_remove; do while read to_remove; do
eval remove_$i=\"${to_remove}\"
i=$(($i+1))
done < "${TMP}"
while [ $i -gt 0 ]; do
eval to_remove=\"remove_$i\"
_techo "Removing ${to_remove} ..." _techo "Removing ${to_remove} ..."
$pcmd rm ${VVERBOSE} -rf "${ddir}/${to_remove}" || \ pcmd echo rm ${VVERBOSE} -rf "${to_remove}" || \
_exit_err "Removing ${to_remove} failed." _exit_err "Removing ${to_remove} failed."
done < "${TMP}" done
fi fi
...@@ -495,55 +503,47 @@ while [ "${i}" -lt "${no_sources}" ]; do ...@@ -495,55 +503,47 @@ 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="$($pcmd cd "${ddir}" && $pcmd ls -tcp1 | grep '/$' | head -n 1)" || \ last_dir="$(pcmd ls -tcp1 "${ddir}" | grep '/$' | head -n 1)" || \
_exit_err "Failed to list contents of ${ddir}." _exit_err "Failed to list contents of ${ddir}."
# #
# clone from old backup, if existing # clone from old backup, if existing
# #
if [ "${rel_last_dir}" ]; then if [ "${last_dir}" ]; then
last_dir="${ddir}/${rel_last_dir}" set -- "$@" "--link-dest=${last_dir}"
# must be absolute, otherwise rsync uses it relative to _techo "Hard linking from ${last_dir}"
# the destination directory. See rsync(1).
abs_last_dir="$(cd "${last_dir}" && pwd -P)" || \
_exit_err "Could not change to last dir ${last_dir}."
set -- "$@" "--link-dest=${abs_last_dir}"
_techo "Hard linking from ${rel_last_dir}"
fi fi
# set time when we really begin to backup, not when we began to remove above # set time when we really begin to backup, not when we began to remove above
destination_date=$(${CDATE}) destination_date=$(${CDATE})
destination_dir="${c_dest}/${INTERVAL}.${destination_date}.$$" destination_dir="${ddir}/${INTERVAL}.${destination_date}.$$"
destination_full="${destination}/${INTERVAL}.${destination_date}.$$"
# give some info # give some info
_techo "Beginning to backup, this may take some time..." _techo "Beginning to backup, this may take some time..."
_techo "Creating ${destination_dir} ..." _techo "Creating ${destination_dir} ..."
mkdir ${VVERBOSE} "${destination_dir}" || \ pcmd mkdir ${VVERBOSE} "${destination_dir}" || \
_exit_err "Creating ${destination_dir} failed. Skipping." _exit_err "Creating ${destination_dir} failed. Skipping."
# absulte now, it's existing
abs_destination_dir="$(cd "${destination_dir}" && pwd -P)" || \
_exit_err "Changing to newly created ${destination_dir} failed. Skipping."
# #
# added marking in 0.6 (and remove it, if successful later) # added marking in 0.6 (and remove it, if successful later)
# #
touch "${abs_destination_dir}.${c_marker}" pcmd touch "${destination_dir}.${c_marker}"
# #
# the rsync part # the rsync part
# #
_techo "Transferring files..." _techo "Transferring files..."
rsync "$@" "${source}" "${abs_destination_dir}"; ret=$? rsync "$@" "${source}" "${destination_full}"; ret=$?
# #
# remove marking here # remove marking here
# #
rm "${abs_destination_dir}.${c_marker}" || \ pcmd rm "${destination_dir}.${c_marker}" || \
_exit_err "Removing ${abs_destination_dir}/${c_marker} failed." _exit_err "Removing ${destination_dir}/${c_marker} failed."
_techo "Finished backup (rsync return code: $ret)." _techo "Finished backup (rsync return code: $ret)."
if [ "${ret}" -ne 0 ]; then if [ "${ret}" -ne 0 ]; then
......
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