Use oldest backup as destination dir without deletion
This commit is contained in:
parent
51dcf4a02f
commit
1e18e71b9d
1 changed files with 24 additions and 11 deletions
27
ccollect
27
ccollect
|
@ -715,6 +715,12 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
|
||||||
fi
|
fi
|
||||||
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?
|
# Check: maximum number of backups is reached?
|
||||||
#
|
#
|
||||||
|
@ -723,7 +729,19 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
|
||||||
_techo "Existing backups: ${count} Total keeping backups: ${c_interval}"
|
_techo "Existing backups: ${count} Total keeping backups: ${c_interval}"
|
||||||
|
|
||||||
if [ "${count}" -ge "${c_interval}" ]; then
|
if [ "${count}" -ge "${c_interval}" ]; then
|
||||||
remove="$((${count} - ${c_interval} + 1))"
|
# 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)..."
|
_techo "Removing ${remove} backup(s)..."
|
||||||
|
|
||||||
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
|
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
|
||||||
|
@ -731,6 +749,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
|
||||||
|
|
||||||
delete_from_file "${TMP}" &
|
delete_from_file "${TMP}" &
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for backup directory to clone from: Always clone from the latest one!
|
# Check for backup directory to clone from: Always clone from the latest one!
|
||||||
|
@ -746,12 +765,6 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
|
||||||
_techo "Hard linking from ${last_dir}"
|
_techo "Hard linking from ${last_dir}"
|
||||||
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}"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Mark backup running and go back to original directory
|
# Mark backup running and go back to original directory
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue