Skip to content
Snippets Groups Projects
Commit 0bce7106 authored by Guillaume Subiron's avatar Guillaume Subiron
Browse files

shellcheck borg handler

parent 6df27e0f
No related branches found
No related tags found
1 merge request!69Multiple improvements in borg handler
#!/bin/bash
# shellcheck shell=bash
# shellcheck disable=SC2154
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
#
......@@ -48,7 +51,7 @@ getconf port
getconf directory
# strip trailing /
directory=${directory%/}
getconf archive {now:%Y-%m-%dT%H:%M:%S}
getconf archive "{now:%Y-%m-%dT%H:%M:%S}"
getconf compression lz4
getconf encryption none
getconf passphrase
......@@ -106,21 +109,23 @@ fi
# check the connection at the source and destination
[ -n "$test" ] || test=0
# shellcheck disable=SC2235
if [ "$host" != "localhost" ] && ([ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]); then
debug "ssh $sshoptions -o PasswordAuthentication=no ${host}${port:+ -p ${port}} -l $user 'echo -n 1'"
local ret=`ssh $sshoptions -o PasswordAuthentication=no ${host}${port:+ -p ${port}} -l $user 'echo -n 1'`
teststr="ssh $sshoptions -o PasswordAuthentication=no ${host}${port:+ -p ${port}} -l $user 'echo -n 1'"
debug "$teststr"
ret=$(su -c "$teststr")
if [ "$ret" = 1 ]; then
debug "Connected to $host as $user successfully"
else
teststr="borg list $options --show-rc -v $execstr_repository"
debug "$teststr"
output=`su -c "$teststr" 2>&1`
output=$(su -c "$teststr" 2>&1)
if echo "$output" | grep "terminating with success status" \
|| echo "$output" | grep "^\S\+ is not a valid repository." \
|| echo "$output" | grep "^Repository \S\+ does not exist."; then
debug "Connected to $host as $user successfully (forced command)"
else
error $output
error "$output"
fatal "Can't connect to $host as $user."
fi
fi
......@@ -132,13 +137,13 @@ if [ "$init" == "yes" ]; then
initstr="borg init $options --encryption=$encryption $execstr_repository"
debug "executing borg init"
debug "$initstr"
if [ $test = 0 ]; then
output="`su -c "$initstr" 2>&1`"
if [ "$test" = 0 ]; then
output="$(su -c "$initstr" 2>&1)"
if [ $? = 2 ]; then
debug $output
debug "$output"
info "Repository was already initialized"
else
warning $output
warning "$output"
warning "Repository has been initialized"
fi
fi
......@@ -168,11 +173,11 @@ IFS=$SAVEIFS
set +o noglob
if [ ! -z $bwlimit ]; then
if [ -n "$bwlimit" ]; then
execstr="${execstr} --remote-ratelimit=${bwlimit}"
fi
if [ ! -z "$create_options" ]; then
if [ -n "$create_options" ]; then
execstr="${execstr} ${create_options}"
fi
......@@ -235,14 +240,14 @@ if [ "$prune" == "yes" ]; then
prunestr="borg prune $options $prune_options $execstr_repository"
debug "executing borg prune"
debug "$prunestr"
if [ $test = 0 ]; then
output="`su -c "$prunestr" 2>&1`"
if [ "$test" = 0 ]; then
output="$(su -c "$prunestr" 2>&1)"
ret=$?
if [ $ret = 0 ]; then
debug $output
debug "$output"
info "Removing old backups succeeded."
elif [ $ret = 1 ]; then
warning $output
warning "$output"
warning "Removing old backups finished with warnings."
else
error $output
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment