Statistiques
| Révision :

root / bin / del-filesystem @ 27

Historique | Voir | Annoter | Télécharger (1,63 ko)

1
#!/bin/bash
2

    
3
function usage {
4
  echo "Description : destroy a ZFS FileSystem." 1>&2
5
  echo "Usage :" 1>&2
6
  echo "$0 [OPTIONS]" 1>&2
7
  echo " -h display this message" 1>&2
8
  echo " -i interactive mode" 1>&2
9
  echo " -n ZFS Volume Name" 1>&2
10

    
11
}
12

    
13
function nointeractive {
14

    
15
MOUNTED=$(zfs get -H mounted $FS_NAME|awk '{ print $3}')
16

    
17
if [ "$MOUNTED" == "no" ]
18
then
19
   is_pool=$(zpool list $FS_NAME)
20
   if [ $? == 1 ]
21
   then
22
      zfs destroy -r $FS_NAME
23
   else
24
      echo "$FS_NAME is a zpool, cannot remove recursively this filesystem" 1>&2
25
      exit 1;
26
   fi 
27
   
28
else
29
   echo "ZFS FileSystem $FS_NAME mounted" 1>&2
30
   exit 1;
31
fi 
32
}
33

    
34

    
35
function interactive {
36

    
37
zfs list
38
echo "*** Enter the ZFS FileSystem Name : ***" 
39
while read inputline
40
do
41
   NAME_VOL=$inputline 
42
   echo "*** Do you want really remove the ZFS FileSystem : $inputline ? (y/n) ***"
43
   while read inputConfirm
44
   do
45
      if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ]
46
      then
47
         break
48
      fi
49
      echo "*** Do you want really remove the ZFS FileSystem : $inputline ? (y/n) ***"
50
   done
51

    
52
   
53
   if [ "$inputConfirm" = "y" ]
54
   then
55
      break
56
   fi
57
   if [ "$inputConfirm" != "y" ]
58
   then
59
      echo "*** Enter the ZFS Volume FileSystem : ***" 
60
   fi
61
done
62
nointeractive
63
}
64

    
65
while getopts "in:h" OPTION
66
do
67
     case $OPTION in
68
         h)
69
             usage
70
             exit 1
71
             ;;
72
         i)
73
             interactive
74
             ;;
75
         n)
76
             FS_NAME=$OPTARG
77
             ;;
78
         r)
79
             ;;
80
         *)
81
             usage
82
             exit 1
83
             ;;
84
     esac
85
done
86

    
87
if [[ -z $FS_NAME ]]
88
then
89
     usage
90
     exit 1
91
fi
92
nointeractive
93

    
94