From 87657bd613a714c2c9cb0c7af8bdb59ffb898c5d Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 3 May 2019 11:21:46 +0200 Subject: initial commit --- check-if-bareos-backup-is-running | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 check-if-bareos-backup-is-running diff --git a/check-if-bareos-backup-is-running b/check-if-bareos-backup-is-running new file mode 100755 index 0000000..b9a7130 --- /dev/null +++ b/check-if-bareos-backup-is-running @@ -0,0 +1,48 @@ +#!/bin/bash + +if [ $# -ne 0 ]; then + >&2 echo 'check-if-bareos-backup-is-running: too many arguments' + exit 2 +fi + +bareos_pid=$( + pgrep -xf '(.*/)?bareos-fd' \ + | head -n1 +) + +if [ -z "${bareos_pid}" ]; then + >&2 echo 'check-if-bareos-backup-is-running: cannot find running bareos-fd' + exit 2 +fi + +if ! grep -qxF bareos-fd "/proc/${bareos_pid}/comm"; then + >&2 echo 'check-if-bareos-backup-is-running: cannot find running bareos-fd' + exit 2 +fi + +if [ $(whoami) != 'root' ]; then + >&2 echo 'check-if-bareos-backup-is-running: must be run as root' + exit 2 +fi + +time_out=$(( + $(date +%s)+30 +)) +was=$( + sed ' + s/^read_bytes: // + t + d + ' "/proc/${bareos_pid}/io" +) +while [ $(date +%s) -le ${time_out} ]; do + sleep 1 + if sed ' + s/^read_bytes: // + t + d + ' "/proc/${bareos_pid}/io" \ + | grep -qvxF "${was}"; then + exit 1 + fi +done -- cgit v1.2.3-70-g09d2