Add support for bandwith limitation

dev
hk 2017-06-07 01:34:35 +02:00
parent ffdf749e8b
commit 8bb2a0e178
2 changed files with 22 additions and 0 deletions

View File

@ -87,6 +87,19 @@ borg_exec () {
${BORG} "$@"
}
limit_bw () {
if ! [[ -x $(command -v pv) ]]; then
>&2 echo "WARNING: BWLIMIT is enabled, but the utility 'pv' is not available. Continuing without bandwith limitation."
return 0
fi
export PV_WRAPPER=$(mktemp)
chmod +x ${PV_WRAPPER}
echo -e '#!/bin/bash\npv -q -L ${BWLIMIT} | "$@"' > ${PV_WRAPPER}
export BWLIMIT
export BORG_RSH="${PV_WRAPPER} ssh"
}
pre_backup_cmd () {
[[ -n ${PRE_BACKUP_CMD} ]] || return 0
echo "Running pre backup command: ${PRE_BACKUP_CMD[@]}"
@ -121,6 +134,7 @@ lock_failed () {
}
exit_clean () {
[[ -n ${PV_WRAPPER} ]] && rm -f ${PV_WRAPPER}
trap - ERR INT TERM
exit $1
}
@ -162,6 +176,10 @@ export BORG_PASSPHRASE
trap 'error_handler ${LINENO} $?' ERR INT TERM
set -o errtrace -o pipefail
if [[ ${BWLIMIT} -gt 0 ]]; then
limit_bw
fi
if [[ ${MODE} == "init" ]]; then
borg_init
elif [[ ${MODE} == "backup" ]]; then

View File

@ -22,6 +22,10 @@ KEEP_WEEKLY=0
KEEP_MONTHLY=24
KEEP_YEARLY=5
# Limit bandwith used when backing up to SSH repositories. Requires the utility `pv`.
# The unit is bytes per second. 0 means no limit.
#BWLIMIT=0
# Change this if you need to have multiple borgwrapper instances running
# using different configs.
#LOCKFILE="/var/lock/borgwrapper.lock"