summaryrefslogtreecommitdiff
path: root/check-if-bareos-backup-is-running
diff options
context:
space:
mode:
Diffstat (limited to 'check-if-bareos-backup-is-running')
-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