From 1faaab09c143ec24436aba2fcfae1fca41077486 Mon Sep 17 00:00:00 2001
From: Emil Breiner <emil.breiner@krumedia.com>
Date: Fri, 4 Sep 2020 17:10:08 +0200
Subject: [PATCH] Make it possible to add custom init_options in borgbackup

Grants the possibility to initialize repositories with custom init_options like '--append-only'.

Change-Id: Icde51728102c9800de1bc166ef8d51ed71793b89
Signed-Off-By: Emil Breiner <emil.breiner@krumedia.com>
---
 handlers/borg.helper.in | 12 ++++++++++++
 handlers/borg.in        |  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/handlers/borg.helper.in b/handlers/borg.helper.in
index c995310..f037836 100644
--- a/handlers/borg.helper.in
+++ b/handlers/borg.helper.in
@@ -284,6 +284,13 @@ do_borg_prune() {
    fi
 
   _prune_done="(DONE)"
+   setDefault init
+}
+
+do_borg_init_options() {
+   inputBox "$borg_title" "Specify custom options for the repository initialization:"
+   [ $? -eq 1 ] && return
+   borg_init_options=$REPLY
    setDefault finish
 }
 
@@ -314,6 +321,7 @@ EOF
 ## for more info see : borg prune -h
 prune = $borg_prune
 keep = "${borg_keep}d"
+init_options = $borg_init_options
 
 [dest]
 directory = $borg_directory
@@ -336,12 +344,14 @@ borg_main_menu() {
       conitem="test connection and destination dir $_con_done"
       encitem="configure encryption mode $_enc_done"
       pruneitem="configure pruning (optional) $_prune_done"
+      inititem="add custom repository'init_options' (optional) $_init_options_done"
       menuBox "$borg_title" "choose a step:" \
          src "$srcitem" \
          dest "$destitem" \
          conn "$conitem" \
          enc "$encitem" \
          prune "$pruneitem" \
+         init "$inititem" \
          finish "finish and create config file"
       [ $? = 0 ] || return
       result="$REPLY"
@@ -351,6 +361,7 @@ borg_main_menu() {
          "conn") do_borg_con;;
          "enc") do_borg_enc;;
          "prune") do_borg_prune;;
+         "init") do_borg_init_options;;
          "finish")
             if [[ "$_con_done$_dest_done$_enc_done$_src_done" != "(DONE)(DONE)(DONE)(DONE)" ]]; then
                msgBox "$borg_title" "You cannot create the configuration file until mandatory steps are completed."
@@ -382,6 +393,7 @@ borg_wizard() {
    borg_encryption=none
    borg_passphrase=
    borg_keep=30
+   borg_init_options=
 
    # Global variables whose '*' shall not be expanded
    set -o noglob
diff --git a/handlers/borg.in b/handlers/borg.in
index 6d9128c..5a27b26 100644
--- a/handlers/borg.in
+++ b/handlers/borg.in
@@ -32,6 +32,7 @@ getconf prune yes
 getconf keep 30d
 getconf prune_options
 getconf cache_directory
+getconf init_options
 
 setsection dest
 getconf user
@@ -98,7 +99,7 @@ fi
 ### INIT IF NEEDED ###
 
 if [ "$init" == "yes" ]; then
-   initstr="borg init --encryption=$encryption $execstr_repository"
+   initstr="borg init --encryption=$encryption $init_options $execstr_repository"
    debug "$initstr"
    if [ $test = 0 ]; then
       output="`su -c "$initstr" 2>&1`"
-- 
GitLab