]> arthur.barton.de Git - AnsibleRoles.git/blob - roles/linux-zfs/templates/zpool-scrub.sh.j2
a0b6cadd509be2881b1a420e5f6c210047644a88
[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 for pool in $pools; do
28         echo "Scrubbing ZFS storage pool \"$pool\" ..."
29         echo -n "Started: "; date
30         zpool scrub "$pool"
31         if [ $? -eq 0 ]; then
32                 wait_for_scrub_done "$pool"
33                 echo -n "Done: "; date
34         else
35                 echo "Failed to start scrubbing!?"
36                 zpool scrub -s "$pool" >/dev/null 2>&1
37                 sleep 5
38         fi
39         echo
40 done
41
42 # Show status of ZFS storage pools
43 zpool status