Statistiques
| Révision :

root / bin / create-volume @ 41

Historique | Voir | Annoter | Télécharger (4,15 ko)

1
#!/bin/bash
2
# $Id: create-volume 41 2013-10-09 08:44:10Z kreverch $
3

    
4
function usage {
5
echo "Syntax :" 1>&2
6
echo "$0 [options]" 1>&2
7
echo " -n : volume name" 1>&2
8
echo " -p : pool name" 1>&2
9
echo " -b : block size. Permit value : 32K, 64K, 128K (recommanded)" 1>&2
10
echo " -s : volume size. Permit unit : T, G, M"  1>&2
11
# FIXME: c'est pas clair ta formulation
12
echo " -o : set property list for a  zfs volume. Separate such property by a ','." 1>&2
13
echo "      Example : -o compression=off,snapdev=visble." 1>&2
14
echo "      Read the man zfs to get the list of the valid properties" 1>&2
15
echo " -i : interactive mode" 1>&2
16
}
17

    
18

    
19
function nointeractive {
20

    
21
if [[ -z $VOL_OPTION ]]
22
then
23
/sbin/zfs create -s -b $BLOCK_SIZE -V $SIZE $NAME_POOL/$NAME
24
else
25
/sbin/zfs create -s -b $BLOCK_SIZE -o $VOL_OPTION -V $SIZE $NAME_POOL/$NAME
26
fi
27

    
28
}
29

    
30

    
31
function interactive {
32
zfs list
33
# FIXME: c'est pas clair ta formulation
34
echo "*** Choose a pool for the ZFS volume to create: ***"
35

    
36
while read inputline
37
do
38
   if [ "$inputline" != "" ]
39
   then
40
      zfs list |grep -i $inputline
41
      if [ $? -eq 1 ]
42
      then
43
# FIXME: c'est pas clair ta formulation
44
         echo "*** Choose a pool for the ZFS volume to create: ***"
45
      else
46

    
47
         echo "*** Are you sure: $inputline ? (y/n) ***"
48
         while read inputConfirm
49
         do
50
            if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ]
51
            then
52
              break
53
            fi
54
            echo "*** Are you sure: $inputline ? (y/n) ***"
55
          done
56

    
57
          if [ "$inputConfirm" = "y" ]
58
          then
59
             NAME_POOL=$inputline
60
             echo "volume name: "
61
             while read inputVolume
62
             do
63
                if [ "$inputVolume" != "" ]
64
                then
65
                   test -d /dev/zvol
66
                   if [ $? -eq 0 ]
67
                   then
68
                      ls -l /dev/zvol/$NAME_POOL/$inputVolume
69
                      if [ $? -eq 0 ]
70
                      then
71
                         echo "volume name already exists"
72
                         VOL_OK=1   
73
                      else
74
                         VOL_OK=0
75
                      fi
76
                   else
77
                      VOL_OK=0 
78
                   fi
79
                   if [ $VOL_OK -eq 1 ]
80
                   then
81
                      echo "volume name: "
82
                   else
83
                      NAME_VOL=$inputVolume
84
                      echo "volume size (Unit in T|G|M): "
85
                      while read inputSize
86
                      do
87
                         if [ "$inputSize" != "" ]
88
                         then
89
                           zfs create -s -b 128K -V $inputSize  $NAME_POOL/$inputVolume
90
                           if [ $? -eq 0 ]
91
                           then
92
                              echo "*** ZFS volume creation [OK] ***" 
93
                              zfs list
94
                              break
95
                           else
96
                              echo "/!\\ ZFS volume creation [ERROR] /!\\"
97
                           fi
98
                        else
99
                           echo "volume size (Unit in T|G|M): "   
100
                        fi
101
                      done
102
                      break
103
                    fi
104
                else
105
                  echo "volume name: "
106
                fi
107
             done
108
             break
109
          fi
110
          break
111
      fi
112
   else
113
# FIXME: c'est pas clair ta formulation
114
      echo "*** Choose a pool for the ZFS volume to create: ***"
115
   fi
116
done
117
}
118

    
119
while getopts "in:p:b:s:o:h" OPTION
120
do
121
     case $OPTION in
122
         h)
123
             usage
124
             exit 1
125
             ;;
126
         i)
127
            interactive
128
            exit 0
129
            ;;
130
         n)
131
           NAME=$OPTARG
132
           ;;
133
         p)
134
           NAME_POOL=$OPTARG
135
           ;;
136
         b)
137
           BLOCK_SIZE=$OPTARG
138
           ;;
139
         s)
140
           SIZE=$OPTARG
141
           ;;
142
         o)
143
           VOL_OPTION=$OPTARG
144
           VOL_OPTION=$(echo $VOL_OPTION|sed -e 's/,/ -o /g')
145
           echo "$VOL_OPTION"
146
           ;;
147
         *)
148
          usage
149
          exit 1
150
          ;;
151
    esac
152
done
153

    
154

    
155
if [[ -z $NAME ]] || [[ -z $NAME_POOL ]] || [[ -z $BLOCK_SIZE ]] || [[ -z $SIZE ]]
156
then
157
     usage
158
     exit 1
159
fi
160
nointeractive