More granular configuration of removing backups of borg

Expanding the options of pruning to hourly, daily, weekly, monthly & yearly in the borg.helper. If set they are included in the pruning command in the handler.

Change-Id: I011b8abf00dc414e03e3caea67d8efa2dc1c526b
This commit is contained in:
Emil Breiner 2020-11-30 12:03:17 +01:00
parent ab8d5a3a39
commit 2f1fb0dc4a
2 changed files with 52 additions and 10 deletions

View File

@ -272,13 +272,21 @@ do_borg_prune() {
declare -a tmp_array declare -a tmp_array
set -o noglob set -o noglob
REPLY= REPLY=
formBegin "$borg_title - keep all backups made within this number of days" formBegin "$borg_title - what backups to keep:"
formItem "keep" "$borg_keep" formItem "hourly" "$borg_keep_hourly"
# for backwards compatibility daily is still named borg_keep
formItem "daily" "$borg_keep"
formItem "weekly" "$borg_keep_weekly"
formItem "monthly" "$borg_keep_monthly"
formItem "yearly" "$borg_keep_yearly"
formDisplay formDisplay
[ $? = 0 ] || return [ $? = 0 ] || return
tmp_array=($REPLY) tmp_array=($REPLY)
borg_keep=${tmp_array[0]} borg_keep_hourly=${tmp_array[0]}
borg_keep=${tmp_array[1]}
borg_keep_weekly=${tmp_array[2]}
borg_keep_monthly=${tmp_array[3]}
borg_keep_yearly=${tmp_array[4]}
set +o noglob set +o noglob
fi fi
@ -312,8 +320,13 @@ EOF
cat >> $next_filename <<EOF cat >> $next_filename <<EOF
## for more info see : borg prune -h ## for more info see : borg prune -h
[prune]
prune = $borg_prune prune = $borg_prune
keep = "${borg_keep}d" keep_hourly = $borg_keep_hourly
keep = $borg_keep
keep_weekly = $borg_keep_weekly
keep_monthly = $borg_keep_monthly
keep_yearly = $borg_keep_yearly
[dest] [dest]
directory = $borg_directory directory = $borg_directory
@ -381,7 +394,14 @@ borg_wizard() {
borg_compression=lz4 borg_compression=lz4
borg_encryption=none borg_encryption=none
borg_passphrase= borg_passphrase=
# pruning
borg_keep_hourly=
# for backwards compatibility daily is still named keep
borg_keep=30 borg_keep=30
borg_keep_weekly=
borg_keep_monthly=
borg_keep_yearly=
# Global variables whose '*' shall not be expanded # Global variables whose '*' shall not be expanded
set -o noglob set -o noglob

View File

@ -28,11 +28,18 @@ getconf init yes
getconf include getconf include
getconf exclude getconf exclude
getconf create_options getconf create_options
getconf prune yes
getconf keep 30d
getconf prune_options
getconf cache_directory getconf cache_directory
setsection prune
getconf prune
getconf keep_hourly
# daily is still named keep for backwards compatibility
getconf keep
getconf keep_weekly
getconf keep_monthly
getconf keep_yearly
getconf prune_options
setsection dest setsection dest
getconf user getconf user
getconf host getconf host
@ -163,9 +170,24 @@ fi
# borg prune # borg prune
if [ "$prune" == "yes" ]; then if [ "$prune" == "yes" ]; then
if [ ! "$keep" == "0" ]; then
prune_options="${prune_options} --keep-within=${keep}" # add the different pruning configurations to the cmd string if set
if [ ! -z "$keep_hourly" ]; then
prune_options="${prune_options} --keep-hourly=$keep_hourly"
fi fi
if [ ! -z "$keep" ]; then
prune_options="${prune_options} --keep-daily=$keep"
fi
if [ ! -z "$keep_weekly" ]; then
prune_options="${prune_options} --keep-weekly=$keep_weekly"
fi
if [ ! -z "$keep_monthly" ]; then
prune_options="${prune_options} --keep-monthly=$keep_monthly"
fi
if [ ! -z "$keep_yearly" ]; then
prune_options="${prune_options} --keep-yearly=$keep_yearly"
fi
prunestr="borg prune $prune_options $execstr_repository" prunestr="borg prune $prune_options $execstr_repository"
debug "$prunestr" debug "$prunestr"
if [ $test = 0 ]; then if [ $test = 0 ]; then