diff --git a/examples/example.borg b/examples/example.borg index b49598d0ab7f9a7bf3dc96cd36eb708412642eb6..4988e9cb61ea3faa97616c09502d44fed2a5a894 100644 --- a/examples/example.borg +++ b/examples/example.borg @@ -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 = diff --git a/handlers/borg.in b/handlers/borg.in index 96490b0cc7a218e26ce52b8d6a0c768b17979b86..6d9128cb928bf37a7942be2828bc2d9d832a3021 100644 --- a/handlers/borg.in +++ b/handlers/borg.in @@ -31,6 +31,7 @@ getconf create_options getconf prune yes getconf keep 30d getconf prune_options +getconf cache_directory setsection dest getconf user @@ -57,6 +58,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