root / bin / del-filesystem @ 40
Historique | Voir | Annoter | Télécharger (1,63 ko)
1 |
#!/bin/bash |
---|---|
2 |
# $Id: del-filesystem 40 2013-10-08 14:37:55Z ltaulell $ |
3 |
|
4 |
function usage { |
5 |
echo "Description : destroy a ZFS FileSystem." 1>&2 |
6 |
echo "Usage :" 1>&2 |
7 |
echo "$0 [OPTIONS]" 1>&2 |
8 |
echo " -h display this message" 1>&2 |
9 |
echo " -i interactive mode" 1>&2 |
10 |
echo " -n ZFS Volume Name" 1>&2 |
11 |
|
12 |
} |
13 |
|
14 |
function nointeractive { |
15 |
|
16 |
MOUNTED=$(zfs get -H mounted $FS_NAME|awk '{ print $3}') |
17 |
|
18 |
if [ "$MOUNTED" == "no" ] |
19 |
then |
20 |
is_pool=$(zpool list $FS_NAME) |
21 |
if [ $? == 1 ] |
22 |
then |
23 |
zfs destroy -r $FS_NAME |
24 |
else |
25 |
echo "$FS_NAME is a zpool, cannot remove recursively this filesystem" 1>&2 |
26 |
exit 1; |
27 |
fi |
28 |
|
29 |
else |
30 |
echo "ZFS FileSystem $FS_NAME mounted" 1>&2 |
31 |
exit 1; |
32 |
fi |
33 |
} |
34 |
|
35 |
|
36 |
function interactive { |
37 |
|
38 |
zfs list |
39 |
echo "*** Enter ZFS FileSystem Name: ***" |
40 |
while read inputline |
41 |
do |
42 |
NAME_VOL=$inputline |
43 |
echo "*** Do you really want to remove this ZFS FileSystem: $inputline ? (y/n) ***" |
44 |
while read inputConfirm |
45 |
do |
46 |
if [ "$inputConfirm" = "y" ]||[ "$inputConfirm" = "n" ] |
47 |
then |
48 |
break |
49 |
fi |
50 |
echo "*** Do you really want to remove this ZFS FileSystem: $inputline ? (y/n) ***" |
51 |
done |
52 |
|
53 |
|
54 |
if [ "$inputConfirm" = "y" ] |
55 |
then |
56 |
break |
57 |
fi |
58 |
if [ "$inputConfirm" != "y" ] |
59 |
then |
60 |
echo "*** Enter ZFS Volume FileSystem: ***" |
61 |
fi |
62 |
done |
63 |
nointeractive |
64 |
} |
65 |
|
66 |
while getopts "in:h" OPTION |
67 |
do |
68 |
case $OPTION in |
69 |
h) |
70 |
usage |
71 |
exit 1 |
72 |
;; |
73 |
i) |
74 |
interactive |
75 |
;; |
76 |
n) |
77 |
FS_NAME=$OPTARG |
78 |
;; |
79 |
r) |
80 |
;; |
81 |
*) |
82 |
usage |
83 |
exit 1 |
84 |
;; |
85 |
esac |
86 |
done |
87 |
|
88 |
if [[ -z $FS_NAME ]] |
89 |
then |
90 |
usage |
91 |
exit 1 |
92 |
fi |
93 |
nointeractive |
94 |
|
95 |
|