diff options
author | Erich Eckner <git@eckner.net> | 2019-05-03 11:21:46 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-05-03 11:21:46 +0200 |
commit | 87657bd613a714c2c9cb0c7af8bdb59ffb898c5d (patch) | |
tree | 0008100cfbb40ad36e510dc69ecf3a0eea88e846 | |
download | check-if-bareos-backup-is-running-87657bd613a714c2c9cb0c7af8bdb59ffb898c5d.tar.xz |
initial commit
-rwxr-xr-x | check-if-bareos-backup-is-running | 48 |
1 files changed, 48 insertions, 0 deletions
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 |