[borg] replace "keep*" options with simpler "keep"

The effect of "keep*" options is not straightforward to understand, so
replacing it with a simpler "keep" option, which replicates the
functionality of other backupninja handlers. This also simplifies the
helper, as the use is then only asked how many days of backups to keep.

At the same time, we add "prune_options" which allows for the use of the
"keep*" options as well as other useful prune options, like "--prefix".
This commit is contained in:
Jerome Charaoui 2018-01-26 11:26:37 -05:00
parent fc0e0849dc
commit f43c85662d
3 changed files with 40 additions and 34 deletions

View File

@ -41,16 +41,6 @@
## Default: ## Default:
# init = yes # init = yes
## how many hours, days, weeks and months of data to keep
##
## for more info see : borg help prune
##
## Default:
# keephourly = 1
# keepdaily = 7
# keepweekly = 4
# keepmonthly = -1
## A few notes about includes and excludes: ## A few notes about includes and excludes:
## 1. include paths do not support any kind of pattern matching ## 1. include paths do not support any kind of pattern matching
## 2. exclude paths support several types of pattern matching, the default being ## 2. exclude paths support several types of pattern matching, the default being
@ -90,6 +80,33 @@ exclude = /var/lib/mysql
## Default: ## Default:
# excludenodump = no # excludenodump = no
## whether to prune (remove) older backups
##
## Default:
# prune = yes
## keep all backups within this time frame.
## must be defined as a number followed by one of the
## following characters: "H", "d", "w", "m", "y"
##
## this option will be ignored if set to 0
##
## the default is to keep all backups made within the
## last 30 days
##
## Default:
# keep = 30d
## define extra command-line options for the "borg prune" operation.
##
## Example:
## prune_options = --keep-daily=7 --keep-weekly=4 --keep-monthly=6
##
## for more info see : borg help prune
##
## Default:
# prune_options =
###################################################### ######################################################
## destination section ## destination section
## (where the files are copied to) ## (where the files are copied to)

View File

@ -270,19 +270,13 @@ do_borg_prune() {
declare -a tmp_array declare -a tmp_array
set -o noglob set -o noglob
REPLY= REPLY=
formBegin "$borg_title - pruning (how many backups to keep)" formBegin "$borg_title - keep all backups made within this number of days"
formItem "hourly" "$borg_keephourly" formItem "keep" "$borg_keep"
formItem "daily" "$borg_keepdaily"
formItem "weekly" "$borg_keepweekly"
formItem "monthly" "$borg_keepmonthly"
formDisplay formDisplay
[ $? = 0 ] || return [ $? = 0 ] || return
tmp_array=($REPLY) tmp_array=($REPLY)
borg_keephourly=${tmp_array[0]} borg_keep=${tmp_array[0]}
borg_keepdaily=${tmp_array[1]}
borg_keepweekly=${tmp_array[2]}
borg_keepmonthly=${tmp_array[3]}
set +o noglob set +o noglob
fi fi
@ -317,10 +311,7 @@ EOF
## for more info see : borg prune -h ## for more info see : borg prune -h
prune = $borg_prune prune = $borg_prune
keephourly = $borg_keephourly keep = "${borg_keep}d"
keepdaily = $borg_keepdaily
keepweekly = $borg_keepweekly
keepmonthly = $borg_keepmonthly
[dest] [dest]
directory = $borg_directory directory = $borg_directory
@ -386,10 +377,7 @@ borg_wizard() {
borg_compression=lz4 borg_compression=lz4
borg_encryption=none borg_encryption=none
borg_passphrase= borg_passphrase=
borg_keephourly=1 borg_keep=30
borg_keepdaily=7
borg_keepweekly=4
borg_keepmonthly=-1
# Global variables whose '*' shall not be expanded # Global variables whose '*' shall not be expanded
set -o noglob set -o noglob

View File

@ -24,15 +24,13 @@ getconf bwlimit
setsection source setsection source
getconf init yes getconf init yes
getconf prune yes
getconf keephourly 1
getconf keepdaily 7
getconf keepweekly 4
getconf keepmonthly -1
getconf include getconf include
getconf exclude getconf exclude
getconf excludecaches no getconf excludecaches no
getconf excludenodump no getconf excludenodump no
getconf prune yes
getconf keep 30d
getconf prune_options
setsection dest setsection dest
getconf user getconf user
@ -153,8 +151,11 @@ fi
# borg prune # borg prune
if [ "$prune" == "yes" ]; then if [ "$prune" == "yes" ]; then
prunestr="borg prune --keep-hourly $keephourly --keep-daily $keepdaily --keep-weekly $keepweekly --keep-monthly $keepmonthly $execstr_repository" if [ ! -z $keep ] && [ ! "$keep" == "0" ]; then
debug "$prunestr" prune_options="${prune_options} --keep-within=${keep}"
fi
prunestr="borg prune $prune_options $execstr_repository"
debug "$prunestr"
if [ $test = 0 ]; then if [ $test = 0 ]; then
output="`su -c "$prunestr" 2>&1`" output="`su -c "$prunestr" 2>&1`"
if [ $? = 0 ]; then if [ $? = 0 ]; then