summaryrefslogtreecommitdiff
path: root/bareos/check-if-bareos-backup-is-running
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-05-03 11:39:38 +0200
committerErich Eckner <git@eckner.net>2019-05-03 11:39:38 +0200
commit3104d1a4e932d37dc8f0565822a8c24414c32d3d (patch)
tree8b2071595cd93f26ac89b00c77a47d1431f54ea5 /bareos/check-if-bareos-backup-is-running
parent8f6246c0f3eaa0d281ea32cb1f2ad5075e0ebf71 (diff)
downloadarchlinuxewe.git.save-3104d1a4e932d37dc8f0565822a8c24414c32d3d.tar.xz
bareos: /usr/bin/check-if-bareos-backup-is-running new
Diffstat (limited to 'bareos/check-if-bareos-backup-is-running')
-rwxr-xr-xbareos/check-if-bareos-backup-is-running48
1 files changed, 48 insertions, 0 deletions
diff --git a/bareos/check-if-bareos-backup-is-running b/bareos/check-if-bareos-backup-is-running
new file mode 100755
index 00000000..b9a71307
--- /dev/null
+++ b/bareos/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