diff --git a/handlers/borg.in b/handlers/borg.in index f98050ca39ca661aaf0e060cdc653ab32f954de2..85900a85e7a4722815602b53a878021bb1949a8e 100644 --- a/handlers/borg.in +++ b/handlers/borg.in @@ -39,21 +39,10 @@ getconf compression lz4 getconf encryption getconf passphrase +export BORG_PASSPHRASE="$passphrase" ### CHECK CONFIG ### -# check the connection at the source and destination -[ -n "$test" ] || test=0 -if [ "$host" != "localhost" ] && ([ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]); then - debug "ssh -o PasswordAuthentication=no $host -l $user 'echo -n 1'" - local ret=`ssh -o PasswordAuthentication=no $host -l $user 'echo -n host is alive'` - if echo $ret | grep "host is alive"; then - debug "Connected to $host as $user successfully" - else - fatal "Can't connect to $host as $user." - fi -fi - # destination specific checks [ "$directory" != "" ] || fatal "Destination directory not set" if [ "$host" != "localhost" ]; then @@ -63,9 +52,31 @@ else fi execstr_archive="$archive" +# check the connection at the source and destination +[ -n "$test" ] || test=0 +if [ "$host" != "localhost" ] && ([ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]); then + debug "ssh -o PasswordAuthentication=no $host -l $user 'echo -n 1'" + local ret=`ssh -o PasswordAuthentication=no $host -l $user 'echo -n 1'` + if [ "$ret" = 1 ]; then + debug "Connected to $host as $user successfully" + else + teststr="borg list --show-rc -v $execstr_repository" + debug "$teststr" + output=`su -c "$teststr" 2>&1` + if echo "$output" | grep "terminating with success status" ; then + debug "Connected to $host as $user successfully (forced command)" + else + if echo "$output" | grep -E "Repository.+does not exist" ; then + debug "Connected to $host as $user successfully (forced command)" + else + fatal "Can't connect to $host as $user." + fi + fi + fi +fi + ### INIT IF NEEDED ### -export BORG_PASSPHRASE="$passphrase" initstr="borg init --encryption=$encryption $execstr_repository" debug "$initstr"