]> arthur.barton.de Git - AnsibleRoles.git/blob - roles/linux-zfs/templates/zpool-scrub.sh.j2
check-mk-agent: Don't setup own systemd service files
[AnsibleRoles.git] / roles / linux-zfs / templates / zpool-scrub.sh.j2
1 #!/bin/bash
2 # /usr/local/sbin/backup-script-wrapper
3 # ---
4 #  {{ ansible_managed }}
5 # ---
6
7 NAME=$(basename "$0")
8
9 pools=$(zpool list -H | cut -f1)
10 if [ $? -ne 0 ]; then
11         echo "$NAME: Failed to list ZFS pools, aborting!"
12         exit 1
13 fi
14 if [ -z "$pools" ]; then
15         # No pools found, nothing to do, ok.
16         exit 0
17 fi
18
19 wait_for_scrub_done() {
20         while true; do
21                 zpool status "$1" 2>/dev/null | fgrep 'scrub in progress' >/dev/null
22                 [ $? -eq 0 ] || return 0
23                 sleep 60
24         done
25 }
26
27 echo "Scrubbing ZFS storage pools on $(hostname -f):"
28 echo
29
30 zpool list
31 echo
32
33 for pool in $pools; do
34         echo "Scrubbing ZFS storage pool \"$pool\" ..."
35         echo -n "Started: "; date
36         zpool scrub "$pool"
37         if [ $? -eq 0 ]; then
38                 wait_for_scrub_done "$pool"
39                 echo -n "Done: "; date
40         else
41                 echo "Failed to start scrubbing!?"
42                 zpool scrub -s "$pool" >/dev/null 2>&1
43                 sleep 5
44         fi
45         echo
46 done
47
48 # Show status of ZFS storage pools
49 zpool status