Statistiques
| Révision :

root / bin / get-disk-zpool @ 49

Historique | Voir | Annoter | Télécharger (2,16 ko)

1
#!/bin/bash
2
# $Id: get-disk-zpool 49 2013-10-10 08:59:11Z kreverch $
3

    
4
BINZFS="/sbin/zfs"
5
BINZPOOL="/sbin/zpool"
6

    
7
function usage {
8

    
9
echo "Syntax $0"
10
echo "Description : Get and write in a file all disk (type raidz and mirror) of a ZFS"
11

    
12
}
13

    
14
function nointeractive {
15
/sbin/zdb >/tmp/.buffer_zdb
16
GETDISKINFO="/sbin/get-disk-info"
17

    
18
dataType=""
19
raidType=""
20
raidID=""
21
nparity=""
22
poolname=""
23

    
24
while read line
25
do
26
   strLine=$(echo $line |sed -e 's/ \+//g'|sed -e "s/'//g")
27
   property=$(echo $strLine |cut -d ':' -f1)
28
   valueProperty=$(echo $strLine |cut -d ':' -f2)
29
   if [ "$property" == "name" ]
30
   then
31
      echo "$property:$valueProperty"
32
      echo "$($BINZPOOL status $valueProperty|grep -i "state:"|sed -e "s/^ \+//g"|sed -e "s/: /:/")"
33
      echo "$($BINZPOOL status $valueProperty|grep -i "scan:"|sed -e "s/^ \+//g"|sed -e "s/: /:/")"
34
      poolname="$valueProperty"
35
   fi
36
   if [[ "$property" =~ "children[" ]]
37
   then
38
       continue;      
39
   fi
40
   if [[ "$property" == "type" ]] && [[ "$valueProperty" == "raidz" ]]
41
   then
42
      dataType="raidz"
43
      raidType="raidz"
44
   fi
45
   
46
   if [[ "$property" == "type" ]] && [[ "$valueProperty" == "mirror" ]]
47
   then
48
      dataType="mirror"
49
      raidType="mirror"
50
   fi
51
  
52
   if [[ "$dataType" == "raidz" ]] || [[ "$dataType" == "mirror" ]]
53
   then
54
      if [ "$property" == "id" ]
55
      then
56
         raidID=$valueProperty
57
         
58
      fi
59
   fi
60
   if [[ "$dataType" == "raidz"  ]] && [[ "$property" == "nparity" ]]
61
   then
62
        nparity="$valueProperty"
63
   fi
64
    
65
   if [[ "$property" == "type" ]] && [[ "$valueProperty" == "disk" ]]
66
   then
67
      dataType="disk"
68
   fi
69
   
70
   if [ "$dataType" == "disk" ]
71
   then
72
      if [[ "$property" == "path" ]] && [[ "$valueProperty" != "" ]]
73
      then
74
        echo "#infoDisk#"
75
        echo "poolname:$poolname"
76
        echo "raidType:$raidType"
77
        echo "nparity:$nparity" 
78
        echo "raidID:$raidID"
79
        echo "$property:$valueProperty"
80
        $GETDISKINFO -d $valueProperty
81
      fi
82
   fi
83
   
84

    
85
done < "/tmp/.buffer_zdb"
86
echo "#infoDisk#"
87
}
88

    
89
while getopts "h" OPTION
90
do
91
     case $OPTION in
92
         h)
93
             usage
94
             exit 1
95
             ;;
96
         *)
97
           usage
98
           exit 1
99
           ;;
100
     esac
101
done
102

    
103
nointeractive