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
35
ccollect
35
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,13 +729,26 @@ 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.
|
||||||
_techo "Removing ${remove} backup(s)..."
|
# 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}" || \
|
# We have something to remove only if count > interval.
|
||||||
_exit_err "Listing old backups failed"
|
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
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -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