Statistiques
| Révision :

root / bin / create-filesystem

Historique | Voir | Annoter | Télécharger (3,09 ko)

1
#!/bin/bash
2
# $Id: create-filesystem 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 : filesystem name" 1>&2
15
echo " -p : pool name" 1>&2
16
echo " -o : set property list for a  zfs volume. Separate such property by a ','." 1>&2
17
echo "      Example : -o compression=off,snapdev=visble." 1>&2
18
echo "      Read the man zfs to get the list of the valid properties" 1>&2
19
echo " -i : interactive mode" 1>&2
20

    
21
}
22

    
23
function nointeractive {
24

    
25
$BINZFS create -o $FS_OPTION $NAME_POOL/$NAME
26

    
27
}
28

    
29

    
30
function interactive {
31
$BINZFS list
32
echo "*** Select the parent zpool : ***"
33

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

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

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

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

    
129
nointeractive