borg: add new setting sshoptions, fixes #11310

This commit is contained in:
Jerome Charaoui 2021-01-09 17:04:24 -05:00
parent fe8778618f
commit c18404eb3a
3 changed files with 43 additions and 6 deletions

View File

@ -206,3 +206,11 @@ exclude = /var/lib/mysql
##
## Default:
# cache_directory =
## command-line options to use with ssh
##
## an example setting would be:
## sshoptions = -i /root/.ssh/id_rsa_borg
##
## Default:
# sshoptions =

View File

@ -49,10 +49,16 @@ getconf archive {now:%Y-%m-%dT%H:%M:%S}
getconf compression lz4
getconf encryption none
getconf passphrase
getconf sshoptions
debug "export BORG_PASSPHRASE=\"<redacted>\""
export BORG_PASSPHRASE="$passphrase"
if [ -n "$sshoptions" ]; then
debug "export BORG_RSH=\"ssh $sshoptions\""
export BORG_RSH="ssh $sshoptions"
fi
### CHECK CONFIG ###
# source includes at least one path
@ -98,8 +104,8 @@ fi
# 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 -p $port -l $user 'echo -n 1'"
local ret=`ssh -o PasswordAuthentication=no $host -p $port -l $user 'echo -n 1'`
debug "ssh $sshoptions -o PasswordAuthentication=no $host -p $port -l $user 'echo -n 1'"
local ret=`ssh $sshoptions -o PasswordAuthentication=no $host -p $port -l $user 'echo -n 1'`
if [ "$ret" = 1 ]; then
debug "Connected to $host as $user successfully"
else
@ -223,4 +229,7 @@ fi
debug "unset BORG_PASSPHRASE"
unset BORG_PASSPHRASE
debug "unset BORG_RSH"
unset BORG_RSH
return 0

View File

@ -243,7 +243,7 @@ finish_borg() {
setconfig dest user "$BN_REMOTEUSER"
setconfig dest host "$BN_REMOTEHOST"
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog "Debug: ssh\s\+-o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testborg::"
}
@ -258,7 +258,7 @@ finish_borg() {
setconfig dest user "$BN_REMOTEUSER"
setconfig dest host "$BN_REMOTEHOST"
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog "Debug: ssh\s\+-o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testborg::"
}
@ -268,7 +268,7 @@ finish_borg() {
setconfig dest host "$BN_REMOTEHOST"
delconfig dest port
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog "Debug: ssh\s\+ -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testborg::"
# defined parameter
@ -276,7 +276,7 @@ finish_borg() {
setconfig dest user "$BN_REMOTEUSER"
setconfig dest host "$BN_REMOTEHOST"
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 7722 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog "Debug: ssh\s\+-o PasswordAuthentication=no ${BN_REMOTEHOST} -p 7722 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:7722${BN_BACKUPDIR}/testborg::"
}
@ -316,6 +316,26 @@ finish_borg() {
greplog 'Debug: executing borg create$' "\s--compression auto,zstd,13\b"
}
@test "check config parameter dest/sshoptions" {
# undefined parameter
setconfig dest user $BN_REMOTEUSER
setconfig dest host $BN_REMOTEHOST
delconfig dest sshoptions
testaction
not_greplog "Debug: export BORG_RSH="
greplog "Debug: ssh\s\+-o PasswordAuthentication=no\s"
greplog "Debug: Connected to ${BN_REMOTEHOST} as ${BN_REMOTEUSER} successfully$"
# defined parameter
setconfig dest user $BN_REMOTEUSER
setconfig dest host $BN_REMOTEHOST
setconfig dest sshoptions "-i /root/.ssh/id_ed25519"
testaction
greplog "Debug: export BORG_RSH=\"ssh -i /root/.ssh/id_ed25519\"$"
greplog "Debug: ssh -i /root/.ssh/id_ed25519 -o PasswordAuthentication=no\s"
greplog "Debug: Connected to ${BN_REMOTEHOST} as ${BN_REMOTEUSER} successfully$"
}
@test "create local backup without encryption" {
# no encryption, no passphrase
setconfig dest archive testarchive