Statistiques
| Révision :

root / bin / create-volume @ 51

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

1
#!/bin/bash
2
# $Id: create-volume 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
echo "Syntax :" 1>&2
13
echo "$0 [options]" 1>&2
14
echo " -n : volume name" 1>&2
15
echo " -p : pool name" 1>&2
16
echo " -b : block size. Permit value : 32K, 64K, 128K (recommanded)" 1>&2
17
echo " -s : volume size. Permit unit : T, G, M"  1>&2
18
echo " -o : set property list for a  zfs volume. Separate such property by a ','." 1>&2
19
echo "      Example : -o compression=off,snapdev=visble." 1>&2
20
echo "      Read the man zfs to get the list of the valid properties" 1>&2
21
echo " -i : interactive mode" 1>&2
22
}
23

    
24

    
25
function nointeractive {
26

    
27
if [[ -z $VOL_OPTION ]]
28
then
29
$BINZFS create -s -b $BLOCK_SIZE -V $SIZE $NAME_POOL/$NAME
30
else
31
$BINZFS create -s -b $BLOCK_SIZE -o $VOL_OPTION -V $SIZE $NAME_POOL/$NAME
32
fi
33

    
34
}
35

    
36

    
37
function interactive {
38
$BINZFS list
39
echo "*** Select the parent zpool : ***"
40

    
41
while read inputline
42
do
43
   if [ "$inputline" != "" ]
44
   then
45
      $BINZFS list |grep -i $inputline
46
      if [ $? -eq 1 ]
47
      then
48
         echo "*** Select the parent zpool ***"
49
      else
50

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

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

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

    
157

    
158
if [[ -z $NAME ]] || [[ -z $NAME_POOL ]] || [[ -z $BLOCK_SIZE ]] || [[ -z $SIZE ]]
159
then
160
     usage
161
     exit 1
162
fi
163
nointeractive