From 731d15eb433332545abc9340abea9401a40f594f Mon Sep 17 00:00:00 2001
From: Olivier Berger <olivier.berger@telecom-sudparis.eu>
Date: Mon, 16 Sep 2024 10:55:33 +0200
Subject: [PATCH] Add support for generic options config value

Allow setting additional parameters at borg invocation time

Inspired from the duplicity handler's options variable

Quick fix for #11349
---
 examples/example.borg   | 7 +++++++
 handlers/borg.helper.in | 7 +++++++
 handlers/borg.in        | 9 +++++----
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/examples/example.borg b/examples/example.borg
index 26f20da..8f536cb 100644
--- a/examples/example.borg
+++ b/examples/example.borg
@@ -11,6 +11,13 @@
 ## destination host and user.
 ##
 
+## passed directly to borg commands, e.g. to use a particular remote
+## borg executable (here: 'borg12'), set this to:
+## options = --remote-path=borg12
+##
+## Default:
+# options =
+
 ## default is 0, but set to 19 if you want to lower the priority.
 ## an example setting would be:
 ## nicelevel = 19
diff --git a/handlers/borg.helper.in b/handlers/borg.helper.in
index c995310..8d1c17b 100644
--- a/handlers/borg.helper.in
+++ b/handlers/borg.helper.in
@@ -294,6 +294,13 @@ do_borg_finish() {
 ## - example.borg
 ## - $borg_docs
 
+## passed directly to borg commands, e.g. to use a particular remote
+## borg executable (here: 'borg12'), set this to:
+## options = --remote-path=borg12
+##
+## Default:
+# options =
+
 [source]
 EOF
    ## includes ##
diff --git a/handlers/borg.in b/handlers/borg.in
index 845f3d5..d31d844 100644
--- a/handlers/borg.in
+++ b/handlers/borg.in
@@ -22,6 +22,7 @@ export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
 
 ### GET CONFIG ###
 
+getconf options
 getconf testconnect yes
 getconf nicelevel 0
 getconf ionicelevel
@@ -109,7 +110,7 @@ if [ "$host" != "localhost" ] && ([ "$testconnect" = "yes" ] || [ "${test}" -eq
    if [ "$ret" = 1 ]; then
       debug "Connected to $host as $user successfully"
    else
-      teststr="borg list --show-rc -v $execstr_repository"
+      teststr="borg list $options --show-rc -v $execstr_repository"
       debug "$teststr"
       output=`su -c "$teststr" 2>&1`
       if echo "$output" | grep "terminating with success status" \
@@ -126,7 +127,7 @@ fi
 ### INIT IF NEEDED ###
 
 if [ "$init" == "yes" ]; then
-   initstr="borg init --encryption=$encryption $execstr_repository"
+   initstr="borg init $options --encryption=$encryption $execstr_repository"
    debug "executing borg init"
    debug "$initstr"
    if [ $test = 0 ]; then
@@ -143,7 +144,7 @@ fi
 
 ### EXECUTE ###
 
-execstr="borg create --stats --compression $compression"
+execstr="borg create $options --stats --compression $compression"
 
 set -o noglob
 
@@ -207,7 +208,7 @@ if [ "$prune" == "yes" ]; then
    if [ ! "$keep" == "0" ]; then
       prune_options="${prune_options} --keep-within=${keep}"
    fi
-   prunestr="borg prune $prune_options $execstr_repository"
+   prunestr="borg prune $options $prune_options $execstr_repository"
    debug "executing borg prune"
    debug "$prunestr"
    if [ $test = 0 ]; then
-- 
GitLab