summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-05-03 11:21:46 +0200
committerErich Eckner <git@eckner.net>2019-05-03 11:21:46 +0200
commit87657bd613a714c2c9cb0c7af8bdb59ffb898c5d (patch)
tree0008100cfbb40ad36e510dc69ecf3a0eea88e846
downloadcheck-if-bareos-backup-is-running-87657bd613a714c2c9cb0c7af8bdb59ffb898c5d.tar.xz
initial commit
-rwxr-xr-xcheck-if-bareos-backup-is-running48
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