borg/borg.sh
Thomas Constans 2e78fb23f2 can use alternate config file via BORG_CONF env var
write statusfile for zabbix monitoring
2025-10-22 11:08:50 +02:00

65 lines
1.4 KiB
Bash
Executable File

#! /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
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
fi
source $conf
TODAY=$(date "+%Y%m%d")
case $1 in
("list")
if [ -v 2 ] ; then
${borg} list ${REPOSITORY}::${2}
ret=$?
else
${borg} list $REPOSITORY
ret=$?
fi
;;
("check")
shift
# if arg: check archive, if not: check whole repo
if [ $# -eq 1 ] ; then
target=${REPOSITORY}::${1}
else
target=${REPOSITORY}
fi
${borg} check -v ${target}
ret=$?
;;
("extract")
${borg} extract ${REPOSITORY}::${2} ${3}
ret=$?
;;
(info)
yesterday=$(date -d "yesterday 13:00 " '+%Y%m%d')
yesterday_archive=${REPOSITORY}::$(hostname)_${yesterday}
$borg check -v $yesterday_archive
ret=$?
;;
(*)
${borg} create --compression lzma,5 $REPOSITORY::$(hostname)_${TODAY} ${src}
ret=$?
test -d $(dirname $statusfile) && echo $ret > $statusfile
if [ $ret -eq 0 ] ; then
${borg} prune $REPOSITORY --prefix $(hostname)_ --keep-daily=${rotate}
fi
;;
esac
exit $ret