Statistiques
| Révision :

root / bin / create-filesystem @ 49

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

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

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

    
7
function usage {
8
echo "Syntax :" 1>&2 
9
echo "$0 [options]" 1>&2
10
echo " -n : filesystem name" 1>&2
11
echo " -p : pool name" 1>&2
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
$BINZFS create -o $FS_OPTION $NAME_POOL/$NAME
22

    
23
}
24

    
25

    
26
function interactive {
27
$BINZFS list
28
echo "*** Select the parent zpool : ***"
29

    
30
while read inputline
31
do
32
   if [ "$inputline" != "" ]
33
   then
34
      $BINZFS list |grep -i $inputline
35
      if [ $? -eq 1 ]
36
      then
37
         echo "*** Select the parent zpool : ***"
38
      else
39

    
40
         echo "*** Are you sure: $inputline ? (y/n) ***"
41
         while read inputConfirm
42
         do
43
            if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ]
44
            then
45
              break
46
            fi
47
            echo "*** Are you sure: $inputline ? (y/n) ***"
48
         done
49

    
50
          if [ "$inputConfirm" = "y" ]
51
          then
52
             NAME_POOL=$inputline
53
             echo "filesystem name: "
54
             while read inputFS
55
             do
56
                if [ "$inputFS" != "" ]
57
                then
58
                   $BINZFS list |grep -i "$inputFS "
59
                   if [ $? -eq 0 ]
60
                   then
61
                         echo "Filesystem name already exists"
62
                         FS_OK=1   
63
                   else
64
                      FS_OK=0 
65
                   fi
66
                   if [ $FS_OK -eq 1 ]
67
                   then
68
                      echo "filesystem name: "
69
                   else
70
                      NAME_FS=$inputFS
71
                           $BINZFS create $NAME_POOL/$inputFS
72
                           if [ $? -eq 0 ]
73
                           then
74
                              echo "*** ZFS filesystem Creation [OK] ***" 
75
                              $BINZFS list
76
                              break
77
                           else
78
                              echo "/!\\ ZFS filesystem Creation [ERROR] /!\\"
79
                           fi
80
                    fi
81
                else
82
                  echo "filesystem name: "
83
                fi
84
             done
85
             break
86
          fi
87
          break
88
      fi
89
   else
90
      echo "*** Select the parent zpool : ***"
91
   fi
92
done
93
}
94

    
95
while getopts "in:p:b:s:o:h" OPTION
96
do
97
     case $OPTION in
98
         h)
99
             usage
100
             exit 1
101
             ;;
102
         i)
103
            interactive
104
            exit 0
105
            ;;
106
         n)
107
           NAME=$OPTARG
108
           ;;
109
         p)
110
           NAME_POOL=$OPTARG
111
           ;;
112
         o)
113
           FS_OPTION=$OPTARG
114
           FS_OPTION=$(echo $FS_OPTION|sed -e 's/,/ -o /g')
115
           echo "$FS_OPTION"
116
           ;;
117
    esac
118
done
119
if [[ -z $NAME_POOL ]] || [[ -z $NAME ]] 
120
then
121
     usage
122
     exit 1
123
fi
124

    
125
nointeractive