Commit 1e18e71b authored by Darko Poljak's avatar Darko Poljak

Use oldest backup as destination dir without deletion

parent 51dcf4a0
......@@ -715,6 +715,12 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
fi
fi
#
# Include current time in name, not the time when we began to remove above
#
export destination_name="${INTERVAL}.$(${CDATE}).$$-${source_no}"
export destination_dir="${ddir}/${destination_name}"
#
# Check: maximum number of backups is reached?
#
......@@ -723,13 +729,26 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
_techo "Existing backups: ${count} Total keeping backups: ${c_interval}"
if [ "${count}" -ge "${c_interval}" ]; then
remove="$((${count} - ${c_interval} + 1))"
_techo "Removing ${remove} backup(s)..."
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
delete_from_file "${TMP}" &
# Use oldest directory as new backup destination directory.
# It need not to be deleted, rsync will sync its content.
oldest_bak=$(ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n 1 || \
_exit_err "Listing oldest backup failed")
_techo "Using ${oldest_bak} for destination dir"
mv "${oldest_bak}" "${destination_dir}" ||
_exit_err "Moving oldest backup ${oldest_bak} to ${destination_dir} failed."
# Touch dest dir so it is not sorted wrong in listings below.
touch "${destination_dir}"
# We have something to remove only if count > interval.
if [ "${count}" -gt "${c_interval}" ]; then
remove="$((${count} - ${c_interval}))"
_techo "Removing ${remove} backup(s)..."
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
delete_from_file "${TMP}" &
fi
fi
#
......@@ -746,12 +765,6 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
_techo "Hard linking from ${last_dir}"
fi
#
# Include current time in name, not the time when we began to remove above
#
export destination_name="${INTERVAL}.$(${CDATE}).$$-${source_no}"
export destination_dir="${ddir}/${destination_name}"
#
# Mark backup running and go back to original directory
#
......
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