Statistiques
| Révision :

root / bin / create-volume @ 46

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

1
#!/bin/bash
2
# $Id: create-volume 46 2013-10-10 05:22:26Z 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
/sbin/zfs list
33
echo "*** Select the parent zpool : ***"
34

    
35
while read inputline
36
do
37
   if [ "$inputline" != "" ]
38
   then
39
      /sbin/zfs list |grep -i $inputline
40
      if [ $? -eq 1 ]
41
      then
42
         echo "*** Select the parent zpool ***"
43
      else
44

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

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

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

    
151

    
152
if [[ -z $NAME ]] || [[ -z $NAME_POOL ]] || [[ -z $BLOCK_SIZE ]] || [[ -z $SIZE ]]
153
then
154
     usage
155
     exit 1
156
fi
157
nointeractive