can use alternate config file via BORG_CONF env var

write statusfile for zabbix monitoring
This commit is contained in:
Thomas Constans 2025-10-22 11:08:50 +02:00
parent a51e957105
commit 2e78fb23f2
2 changed files with 17 additions and 7 deletions

View File

@ -2,4 +2,5 @@ REPOSITORY={{borg_account}}@{{ borg_server }}:{{ borg_remote_dir }}/{{ ansible_h
export BORG_PASSPHRASE={{ borg_passphrase }} export BORG_PASSPHRASE={{ borg_passphrase }}
borg=/usr/bin/borg borg=/usr/bin/borg
rotate={{ borg_rotate }} rotate={{ borg_rotate }}
src="{{ borg_dirs }}" src="{{ borg_dirs }}"
statusfile=/run/zabbix/borg.status

21
borg.sh Normal file → Executable file
View File

@ -1,9 +1,17 @@
#! /bin/bash #! /bin/bash
set -euo pipefail
# wrapper around borgbackup # wrapper around borgbackup
# need a borg.conf file - see example file # need a borg.conf file - see example file
# alternate conf file can be passed through BORG_CONF env variable
# need passwordless ssh access if using remote repo # need passwordless ssh access if using remote repo
conf=$(dirname $0)/borg.conf
if [ -v BORG_CONF ] ; then
conf=$BORG_CONF
else
conf=$(dirname $0)/borg.conf
fi
if [ ! -f $conf ] ; then if [ ! -f $conf ] ; then
echo config file not found echo config file not found
exit 5 exit 5
@ -15,11 +23,11 @@ TODAY=$(date "+%Y%m%d")
case $1 in case $1 in
("list") ("list")
if [ ! -z $2 ] ; then if [ -v 2 ] ; then
${borg} list $options ${REPOSITORY}::${2} ${borg} list ${REPOSITORY}::${2}
ret=$? ret=$?
else else
${borg} list $options $REPOSITORY ${borg} list $REPOSITORY
ret=$? ret=$?
fi fi
;; ;;
@ -46,10 +54,11 @@ case $1 in
ret=$? ret=$?
;; ;;
(*) (*)
${borg} create $options --compression lzma,5 $REPOSITORY::$(hostname)_${TODAY} ${src} ${borg} create --compression lzma,5 $REPOSITORY::$(hostname)_${TODAY} ${src}
ret=$? ret=$?
test -d $(dirname $statusfile) && echo $ret > $statusfile
if [ $ret -eq 0 ] ; then if [ $ret -eq 0 ] ; then
${borg} prune $options $REPOSITORY --prefix $(hostname)_ --keep-daily=${rotate} ${borg} prune $REPOSITORY --prefix $(hostname)_ --keep-daily=${rotate}
fi fi
;; ;;
esac esac