diff --git a/borg.conf b/borg.conf index 1650104..bda7c1f 100644 --- a/borg.conf +++ b/borg.conf @@ -2,4 +2,5 @@ REPOSITORY={{borg_account}}@{{ borg_server }}:{{ borg_remote_dir }}/{{ ansible_h export BORG_PASSPHRASE={{ borg_passphrase }} borg=/usr/bin/borg rotate={{ borg_rotate }} -src="{{ borg_dirs }}" \ No newline at end of file +src="{{ borg_dirs }}" +statusfile=/run/zabbix/borg.status \ No newline at end of file diff --git a/borg.sh b/borg.sh old mode 100644 new mode 100755 index 92633ff..6e7ae97 --- a/borg.sh +++ b/borg.sh @@ -1,9 +1,17 @@ #! /bin/bash +set -euo pipefail # wrapper around borgbackup # 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 -conf=$(dirname $0)/borg.conf + +if [ -v BORG_CONF ] ; then + conf=$BORG_CONF +else + conf=$(dirname $0)/borg.conf +fi + if [ ! -f $conf ] ; then echo config file not found exit 5 @@ -15,11 +23,11 @@ TODAY=$(date "+%Y%m%d") case $1 in ("list") - if [ ! -z $2 ] ; then - ${borg} list $options ${REPOSITORY}::${2} + if [ -v 2 ] ; then + ${borg} list ${REPOSITORY}::${2} ret=$? else - ${borg} list $options $REPOSITORY + ${borg} list $REPOSITORY ret=$? fi ;; @@ -46,10 +54,11 @@ case $1 in ret=$? ;; (*) - ${borg} create $options --compression lzma,5 $REPOSITORY::$(hostname)_${TODAY} ${src} + ${borg} create --compression lzma,5 $REPOSITORY::$(hostname)_${TODAY} ${src} ret=$? + test -d $(dirname $statusfile) && echo $ret > $statusfile if [ $ret -eq 0 ] ; then - ${borg} prune $options $REPOSITORY --prefix $(hostname)_ --keep-daily=${rotate} + ${borg} prune $REPOSITORY --prefix $(hostname)_ --keep-daily=${rotate} fi ;; esac