borg: add configuration to displace the cache directory

borg will by default create its cache directory in ~/.cache/borg. This
means that during backup runs, borg will read and write quite
extensively from/to this directory.

In some situations, it is rather undesirable to have this amount of IO
activity in this location and it would make sense to tell borg to place
its cache elsewhere. This can help for example with placing the cache on
a hard drive where the added IO load will not have as big of an impact
on other running activity for the system.

This change also makes sure that the cache directory environment
variable is cleared out when the configuration option is unset. This
should avoid unpleasant surprises when this environment variable is set
to some unknown value in the context where backupninja is called, which
could lead to borg reading and writing to random places on the system.
This commit is contained in:
LeLutin 2020-08-14 05:46:34 -07:00 committed by Guillaume Subiron
parent f9529d1d3f
commit e28da8c390
2 changed files with 21 additions and 0 deletions

View File

@ -180,3 +180,9 @@ exclude = /var/lib/mysql
##
## Default:
# passphrase =
## Path to the directory that will hold borg's cache files. By default this is
## empty, which will let borg use its default path of "~/.cache/borg".
##
## Default:
# cache_directory =

View File

@ -31,6 +31,7 @@ getconf create_options
getconf prune yes
getconf keep 30d
getconf prune_options
getconf cache_directory
setsection dest
getconf user
@ -56,6 +57,20 @@ else
fi
execstr_archive="$archive"
if [ -n "$cache_directory" ]; then
cache_parent_dir=$(dirname "$(readlink -f "$cache_directory")")
[ -d "$cache_parent_dir" ] || fatal "Cache directory parent dir '$cache_parent_dir' is absent or is not a directory."
BORG_CACHE_DIR=$cache_directory
export BORG_CACHE_DIR
else
# Cache dir not set, let's clear out the environment variable to avoid
# having this directory be pointed to a random destination.
# Also apparently if we set the variable to an empty string, borg uses the
# empty string as though it was some path we specified and backup runs
# error out, so we need to unset the variable completely.
unset BORG_CACHE_DIR
fi
# check the connection at the source and destination
[ -n "$test" ] || test=0
if [ "$host" != "localhost" ] && ([ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]); then