Skip to content
Snippets Groups Projects
Commit 97153e44 authored by Christopher Gervais's avatar Christopher Gervais
Browse files

Remove duplication in setting 'keep' parameters.

parent 8272e549
No related branches found
No related tags found
No related merge requests found
...@@ -116,50 +116,26 @@ if [[ "$retention" == "yes" ]]; then ...@@ -116,50 +116,26 @@ if [[ "$retention" == "yes" ]]; then
fi fi
fi fi
if [ $keep_hourly ]; then declare -A range_array
if [[ $keep_hourly =~ ^[0-9]+$ ]]; then range_array['hourly']="hour"
debug "==> For the last $keep_hourly hours in which a snapshot was made, keep only the last snapshot for each hour." range_array['daily']="day"
keep_options="$keep_options --keep-hourly $keep_hourly" range_array['weekly']="week"
range_array['monthly']="month"
range_array['yearly']="year"
for range in "${!range_array[@]}" ; do
keep_range="keep_${range}"
keep_unit="${range_array[$range]}"
if [ "${!keep_range}" ]; then
if [[ "${!keep_range}" =~ ^[0-9]+$ ]]; then
debug "==> For the last ${!keep_range} ${keep_unit}s in which a snapshot was made, keep only the last snapshot for each ${keep_unit}."
keep_options="$keep_options --keep-$range ${!keep_range}"
else else
fatal "If 'keep_hourly' is set, it must be an integer." fatal "If 'keep_$range' is set, it must be an integer."
fi fi
fi fi
if [ $keep_daily ]; then done
if [[ $keep_daily =~ ^[0-9]+$ ]]; then
debug "==> For the last $keep_daily days which have one or more snapshots, only keep the last one for that day."
keep_options="$keep_options --keep-daily $keep_daily"
else
fatal "If 'keep_daily' is set, it must be an integer."
fi
fi
if [ $keep_weekly ]; then
if [[ $keep_weekly =~ ^[0-9]+$ ]]; then
debug "==> For the last $keep_weekly weeks which have one or more snapshots, only keep the last one for that week."
keep_options="$keep_options --keep-weekly $keep_weekly"
else
fatal "If 'keep_weekly' is set, it must be an integer."
fi
fi
if [ $keep_monthly ]; then
if [[ $keep_monthly =~ ^[0-9]+$ ]]; then
debug "==> For the last $keep_monthly months which have one or more snapshots, only keep the last one for that month."
keep_options="$keep_options --keep-monthly $keep_monthly"
else
fatal "If 'keep_monthly' is set, it must be an integer."
fi
fi
if [ $keep_yearly ]; then
if [[ $keep_yearly =~ ^[0-9]+$ ]]; then
debug "==> For the last $keep_yearly years which have one or more snapshots, only keep the last one for that year."
keep_options="$keep_options --keep-yearly $keep_yearly"
else
fatal "If 'keep_yearly' is set, it must be an integer."
fi
fi
if [ $keep_tag ]; then if [ $keep_tag ]; then
for tag in $keep_tag for tag in $keep_tag
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment