summaryrefslogtreecommitdiff
path: root/check-if-bareos-backup-is-running
blob: b9a71307de7457f85d617551669ce2c858284a57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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