Added initial support for cloning from different intervals

This commit is contained in:
Nico Schottelius 2007-08-16 21:11:13 +02:00
parent 11a2b5a6ba
commit 86960388df

View file

@ -405,11 +405,11 @@ while [ "${i}" -lt "${no_sources}" ]; do
done < "${TMP}" done < "${TMP}"
) || _exit_err "Searching for incomplete backups failed." ) || _exit_err "Searching for incomplete backups failed."
# #
# 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=$(cd "${c_dest}" && ls -p1 | grep "^${INTERVAL}\..*/\$" | wc -l \
| sed 's/^ *//g') || _exit_err "Counting backups failed" | sed 's/^ *//g') || _exit_err "Counting backups failed"
@ -427,46 +427,51 @@ while [ "${i}" -lt "${no_sources}" ]; do
while read to_remove; do while read to_remove; do
_techo "Removing ${to_remove} ..." _techo "Removing ${to_remove} ..."
rm $VVERBOSE -rf "$to_remove" # FIXME DEBUG
echo rm $VVERBOSE -rf "$to_remove"
done < "${TMP}" done < "${TMP}"
) || _exit_err " ) || _exit_err "Problem removing old backups"
fi fi
#last_dir=$(ls -d "${c_dest}/${INTERVAL}."?* 2>/dev/null | sort -n | tail -n 1)
# #
# Check for backup directory to clone from # Check for backup directory to clone from
# #
found_old=0
( # try our interval
# can we use ls? or will it produce broken results? set -x
#cd "${c_dest}" && ls -dp1 | grep "^${INTERVAL}\..*/\$" | wc -l | sed 's/^ *//g') last_dir="$(ls -d "${c_dest}/${INTERVAL}."?* 2>/dev/null | sort -n | tail -n 1)"
cd "${c_dest}" && ls -dp1 "${INTERVAL}".* > "${TMP}"
) # try other intervals, if there's none four our interval
while read old; do if [ -z "${last_dir}" ]; then
echo "Found ${old}" _techo "Did not find existing backups for interval ${INTERVAL}."
# get list
: > "${TMP}"
( cd "${backup}/intervals/" 2>/dev/null && ls >> "${TMP}" )
( cd "${CDEFAULTS}/intervals/" 2>/dev/null && ls >> "${TMP}" )
# FIXME in 0.6.1: choose best source, not first one.
while read other_interval; do
last_dir="$(ls -d "${c_dest}/${other_interval}."?* 2>/dev/null | sort -n | tail -n 1)"
if [ "${last_dir}" ]; then
_techo "Using backup from ${other_interval}."
break
fi
done < "${TMP}" done < "${TMP}"
fi
# # set time when we really begin to backup, not when we began to remove above
# Check for backups on other intervals, if we did not find any destination_date=$(${CDATE})
# destination_dir="${c_dest}/${INTERVAL}.${destination_date}.$$"
#
# clone the old directory with hardlinks
#
destination_date=$($CDATE)
destination_dir="$c_dest/${INTERVAL}.${destination_date}.$$"
#
# FIXME: In 0.6 add search for the latest available backup!
#
last_dir=$(ls -d "$c_dest/${INTERVAL}."?* 2>/dev/null | sort -n | tail -n 1)
# give some info # give some info
echo "Beginning to backup, this may take some time..." _techo "Beginning to backup, this may take some time..."
echo "Creating $destination_dir ..." echo "Creating ${destination_dir} ..."
mkdir $VVERBOSE "$destination_dir" || \ mkdir ${VVERBOSE} "${destination_dir}" || \
_exit_err "Creating $destination_dir failed. Skipping." _exit_err "Creating $destination_dir failed. Skipping."
# #
@ -493,7 +498,8 @@ while [ "${i}" -lt "${no_sources}" ]; do
# #
set -x set -x
rsync "$@" "$source" "$abs_destination_dir"; ret=$? rsync "$@" "${source}" "${abs_destination_dir}"; ret=$?
# abs_last_dir="$(cd "$last_dir" && pwd -P)" # abs_last_dir="$(cd "$last_dir" && pwd -P)"
# if [ -z "$abs_last_dir" ]; then # if [ -z "$abs_last_dir" ]; then
# echo "Changing to the last backup directory failed. Skipping." # echo "Changing to the last backup directory failed. Skipping."
@ -501,18 +507,15 @@ while [ "${i}" -lt "${no_sources}" ]; do
# fi # fi
# rsync_hardlink="--link-dest=$abs_last_dir" # rsync_hardlink="--link-dest=$abs_last_dir"
set +x
if [ "$ret" -ne 0 ]; then
echo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)."
fi
# #
# remove marking here # remove marking here
# #
rm -f "${abs_destination_dir}/${c_marker}" rm -f "${abs_destination_dir}/${c_marker}"
_techo "Finished backup (rsync return code: $ret)." _techo "Finished backup (rsync return code: $ret)."
if [ "$ret" -ne 0 ]; then
_techo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)."
fi
# #
# post_exec # post_exec