Statistiques
| Révision :

root / bin / get-disk-zpool

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

1
#!/bin/bash
2
# $Id: get-disk-zpool 51 2013-10-10 11:20:37Z ltaulell $
3
# Copyright (C) 2013 Kevin Reverchon, Loïs Taulelle
4
# This file/program is part of gZFS free software
5
# See COPYING file for details
6
#
7

    
8
BINZFS="/sbin/zfs"
9
BINZPOOL="/sbin/zpool"
10

    
11
function usage {
12

    
13
echo "Syntax $0"
14
echo "Description : Get and write in a file all disk (type raidz and mirror) of a ZFS"
15

    
16
}
17

    
18
function nointeractive {
19
/sbin/zdb >/tmp/.buffer_zdb
20
GETDISKINFO="/sbin/get-disk-info"
21

    
22
dataType=""
23
raidType=""
24
raidID=""
25
nparity=""
26
poolname=""
27

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

    
89
done < "/tmp/.buffer_zdb"
90
echo "#infoDisk#"
91
}
92

    
93
while getopts "h" OPTION
94
do
95
     case $OPTION in
96
         h)
97
             usage
98
             exit 1
99
             ;;
100
         *)
101
           usage
102
           exit 1
103
           ;;
104
     esac
105
done
106

    
107
nointeractive