Create status file for external monitoring.

Remove hooks, as they do nothing that a wrapper can't do for you
in their current state (pre and post)
dev
hkbakke 2017-09-07 13:54:19 +02:00
parent 5fd3dce8c1
commit 72f722e3b3
2 changed files with 33 additions and 32 deletions

View File

@ -109,6 +109,24 @@ borg_exec () {
${BORG} "$@" ${BORG} "$@"
} }
write_backup_status () {
local NAME=$(basename "${CONFIG}" .sh)
local STATUSFILE="${STATUSDIR}/${NAME}.backup"
local STATUS="$1"
mkdir -p "${STATUSDIR}"
echo "$(date +'%s') ${STATUS}" > "${STATUSFILE}"
}
write_verify_status () {
local NAME=$(basename "${CONFIG}" .sh)
local STATUSFILE="${STATUSDIR}/${NAME}.verify"
local STATUS="$1"
mkdir -p "${STATUSDIR}"
echo "$(date +'%s') ${STATUS}" > "${STATUSFILE}"
}
convert_rate () { convert_rate () {
# Convert IN_RATE to bytes # Convert IN_RATE to bytes
local IN_RATE=${1} local IN_RATE=${1}
@ -151,31 +169,23 @@ limit_bw () {
echo "Limiting bandwith to ${RATE_LIMIT} bytes/s" echo "Limiting bandwith to ${RATE_LIMIT} bytes/s"
} }
pre_backup_cmd () {
[[ -n ${PRE_BACKUP_CMD} ]] || return 0
echo "Running pre backup command: ${PRE_BACKUP_CMD[@]}"
"${PRE_BACKUP_CMD[@]}"
}
post_backup_cmd () {
[[ -n ${POST_BACKUP_CMD} ]] || return 0
echo "Running post backup command: ${POST_BACKUP_CMD[@]}"
"${POST_BACKUP_CMD[@]}"
}
post_verify_cmd () {
[[ -n ${POST_VERIFY_CMD} ]] || return 0
echo "Running post verify command: ${POST_VERIFY_CMD[@]}"
"${POST_VERIFY_CMD[@]}"
}
exit_backup () { exit_backup () {
post_backup_cmd if [[ $1 -eq 0 ]]; then
write_backup_status "OK"
else
write_backup_status "FAILED"
fi
exit_clean $1 exit_clean $1
} }
exit_verify () { exit_verify () {
post_verify_cmd if [[ $1 -eq 0 ]]; then
write_verify_status "OK"
else
write_verify_status "FAILED"
fi
exit_clean $1 exit_clean $1
} }
@ -197,6 +207,7 @@ CONFIG="/etc/borgwrapper/config.sh"
DRY_RUN=false DRY_RUN=false
BORG="/usr/bin/borg" BORG="/usr/bin/borg"
LOCKDIR="/run/lock/borgwrapper" LOCKDIR="/run/lock/borgwrapper"
STATUSDIR="/var/lib/borgwrapper/status"
PRE_BACKUP_CMD=() PRE_BACKUP_CMD=()
POST_BACKUP_CMD=() POST_BACKUP_CMD=()
POST_VERIFY_CMD=() POST_VERIFY_CMD=()
@ -252,7 +263,6 @@ mkdir -p "${LOCKDIR}"
borg_init borg_init
elif [[ ${MODE} == "backup" ]]; then elif [[ ${MODE} == "backup" ]]; then
trap 'exit_backup $?' ERR INT TERM trap 'exit_backup $?' ERR INT TERM
pre_backup_cmd
borg_backup borg_backup
borg_prune borg_prune
exit_backup 0 exit_backup 0

View File

@ -30,17 +30,8 @@ KEEP_YEARLY=5
# Location of borgwrapper lock files # Location of borgwrapper lock files
#LOCKDIR="/run/lock/borgwrapper" #LOCKDIR="/run/lock/borgwrapper"
# Command to execute before backup, e.g., taking a ZFS snapshot. Must return successfully # Location of borgwrapper status files for external monitoring
# for backup to start. POST_BACKUP_CMD is executed even if this fails. #STATUSDIR="/var/lib/borgwrapper/status"
#PRE_BACKUP_CMD=()
# Command to execute after backup, e.g., removing a snapshot or sending a report somewhere.
# This command is executed regardless of backup success.
#POST_BACKUP_CMD=()
# Command to execute after verification.
# This command is executed regardless of verification success.
#POST_VERIFY_CMD=()
# Optional arguments to the different borg commands. # Optional arguments to the different borg commands.
# The current default values are listed. Modify if needed. # The current default values are listed. Modify if needed.