Allow interval per source to be overwritten to 0 to skip the source in this interval. #2

Open
skybeam wants to merge 3 commits from skybeam/ccollect:master into master
2 changed files with 19 additions and 2 deletions

View file

@ -765,7 +765,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
oldest_bak=$(ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n 1 || \ oldest_bak=$(ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n 1 || \
_exit_err "Listing oldest backup failed") _exit_err "Listing oldest backup failed")
_techo "Using ${oldest_bak} for destination dir ${destination_dir}" _techo "Using ${oldest_bak} for destination dir ${destination_dir}"
if mv "${oldest_bak}" "${destination_dir}"; then if mv "${oldest_bak}" "${destination_dir}" 2>/dev/null; then
Review

Why skip potential error messages?

Why skip potential error messages?
Review

Because oldest_bak can be empty and this causing mv to spit an error - which is OK as we are only interested in the return code telling us if the move was successful. In this case the failed move is expected. No need for an error message.

Because oldest_bak can be empty and this causing mv to spit an error - which is OK as we are only interested in the return code telling us if the move was successful. In this case the failed move is expected. No need for an error message.
# Touch dest dir so it is not sorted wrong in listings below. # Touch dest dir so it is not sorted wrong in listings below.
ls_rm_exclude=$(basename "${destination_dir}") ls_rm_exclude=$(basename "${destination_dir}")
@ -779,7 +779,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
if [ "${remove}" -gt 0 ]; then if [ "${remove}" -gt 0 ]; then
_techo "Removing ${remove} backup(s)..." _techo "Removing ${remove} backup(s)..."
if [ -z "${ls_rm_exclude}" ]; then if [ -z "${ls_rm_exclude}" -o ${c_interval} -eq 0 ]; then
# shellcheck disable=SC2010 # shellcheck disable=SC2010
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \ ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed" _exit_err "Listing old backups failed"
@ -793,6 +793,14 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
fi fi
fi fi
#
# Skip backup of this source if interval is zero.
#
if [ ${c_interval} -eq 0 ]; then
_techo "Skipping backup for this interval."
exit 0
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!
# Exclude destination_dir from listing, it can be touched reused and renamed # Exclude destination_dir from listing, it can be touched reused and renamed

View file

@ -339,6 +339,9 @@ Example:
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
This means to keep 28 daily backups, 12 monthly backups and 4 weekly. This means to keep 28 daily backups, 12 monthly backups and 4 weekly.
If you set a value of 0 the interval will be skipped. This is useful mainly on
source level in order to skip a certain interval for a specific source.
General pre- and post-execution General pre- and post-execution
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -420,6 +423,12 @@ Example:
/home/nico/vpn /home/nico/vpn
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
You can overwrite a default interval at source level. Setting it to 0 will skip
this interval on a specific source allowing you to skip an interval for a
specific source only while keeping source-specific interval amounts (or default
values) for any other source.
Default options Default options
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
If you add '$CCOLLECT_CONF/defaults/`option_name`', the value will If you add '$CCOLLECT_CONF/defaults/`option_name`', the value will