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