From fc0e0849dc8fc3f8787dd28226b5f4be425e26bf Mon Sep 17 00:00:00 2001
From: Jerome Charaoui <jerome@riseup.net>
Date: Fri, 26 Jan 2018 09:53:54 -0500
Subject: [PATCH] [borg] add init option to allow skipping init command

In some cases it may be desirable to skip repository initialization, for
example when the repository is located at the root of a mount point.
---
 examples/example.borg |  6 ++++++
 handlers/borg.in      | 25 +++++++++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/examples/example.borg b/examples/example.borg
index 244dbc8..8644cbc 100644
--- a/examples/example.borg
+++ b/examples/example.borg
@@ -35,6 +35,12 @@
 
 [source]
 
+## default is to initialize the backup repository if absent
+## set to no to skip this step
+##
+## Default:
+# init = yes
+
 ## how many hours, days, weeks and months of data to keep
 ##
 ## for more info see : borg help prune
diff --git a/handlers/borg.in b/handlers/borg.in
index 0e88390..698ba6d 100644
--- a/handlers/borg.in
+++ b/handlers/borg.in
@@ -23,6 +23,7 @@ getconf nicelevel 0
 getconf bwlimit
 
 setsection source
+getconf init yes
 getconf prune yes
 getconf keephourly 1
 getconf keepdaily 7
@@ -82,18 +83,18 @@ fi
 
 ### INIT IF NEEDED ###
 
-initstr="borg init --encryption=$encryption $execstr_repository"
-
-debug "$initstr"
-
-if [ $test = 0 ]; then
-   output="`su -c "$initstr" 2>&1`"
-   if [ $? = 2 ]; then
-      debug $output
-      info "Repository was already initialized"
-   else
-      warning $output
-      warning "Repository has been initialized"
+if [ "$init" == "yes" ]; then
+   initstr="borg init --encryption=$encryption $execstr_repository"
+   debug "$initstr"
+   if [ $test = 0 ]; then
+      output="`su -c "$initstr" 2>&1`"
+      if [ $? = 2 ]; then
+         debug $output
+         info "Repository was already initialized"
+      else
+         warning $output
+         warning "Repository has been initialized"
+      fi
    fi
 fi
 
-- 
GitLab