Use oldest backup as destination dir without deletion

This commit is contained in:
Darko Poljak 2019-10-17 07:42:31 +02:00
parent 51dcf4a02f
commit 1e18e71b9d
1 changed files with 24 additions and 11 deletions

View File

@ -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)..."
# 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}"
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
# We have something to remove only if count > interval.
if [ "${count}" -gt "${c_interval}" ]; then
remove="$((${count} - ${c_interval}))"
_techo "Removing ${remove} backup(s)..."
delete_from_file "${TMP}" &
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
#