root / bin / disable-snapshot @ 49
Historique | Voir | Annoter | Télécharger (2,48 ko)
1 |
#!/bin/bash |
---|---|
2 |
# $Id: disable-snapshot 49 2013-10-10 08:59:11Z kreverch $ |
3 |
|
4 |
DIR_CRON="/etc/cron.d/" |
5 |
DIR_CONF_SNAPSHOT="/opt/gZFS/snapshots/" |
6 |
BIN_ZFS_SNAPSHOT="/sbin/zfs-snapshot" |
7 |
BINZFS="/sbin/zfs" |
8 |
BINZPOOL="/sbin/zpool" |
9 |
|
10 |
|
11 |
function usage { |
12 |
echo "Usage :" 1>&2 |
13 |
echo "disable-snapshot [OPTIONS]" 1>&2 |
14 |
echo " -h display this message" 1>&2 |
15 |
echo " -i interactive mode" 1>&2 |
16 |
echo " -N Specify the name ZFS Volume/Filesystem" 1>&2 |
17 |
|
18 |
} |
19 |
|
20 |
function nointeractive { |
21 |
FILE_NAME=$(echo "snapshot-"${NAMEZFS//\//-}) |
22 |
/bin/rm -f $DIR_CONF_SNAPSHOT$FILE_NAME.conf |
23 |
if [ -e $DIR_CONF_SNAPSHOT$FILE_NAME.conf ] |
24 |
then |
25 |
echo "Error : cannot delete $DIR_CONF_SNAPSHOT$FILE_NAME.conf" |
26 |
fi |
27 |
|
28 |
/bin/rm $DIR_CRON$FILE_NAME |
29 |
if [ -e $DIR_CRON$FILE_NAME ] |
30 |
then |
31 |
echo "Error : cannot delete $DIR_CRON$FILE_NAME" |
32 |
fi |
33 |
|
34 |
} |
35 |
|
36 |
function interactive { |
37 |
|
38 |
$BINZFS list |
39 |
echo "*** Nom du volume pour desactiver les snapshot :" |
40 |
while read inputline |
41 |
do |
42 |
if [ "$inputline" != "" ] |
43 |
then |
44 |
$BINZFS list $inputline |
45 |
if [ $? -eq 0 ] |
46 |
then |
47 |
FILE_NAME=$(echo "snapshot-"${inputline//\//-}) |
48 |
if [ -e $DIR_CONF_SNAPSHOT$FILE_NAME.conf ] |
49 |
then |
50 |
/bin/rm -f $DIR_CONF_SNAPSHOT$FILE_NAME.conf |
51 |
if [ $? -eq 0 ] |
52 |
then |
53 |
echo "*** Suppression du fichier conf $DIR_CONF_SNAPSHOT$FILE_NAME.conf [OK]" |
54 |
else |
55 |
echo "/!\\ Suppression du fichier $DIR_CONF_SNAPSHOT$FILE_NAME.conf [ERROR] /!\\" |
56 |
exit |
57 |
fi |
58 |
else |
59 |
echo "*** Le fichier de conf $DIR_CONF_SNAPSHOT$FILE_NAME.conf n'existe pas" |
60 |
fi |
61 |
|
62 |
if [ -e $DIR_CRON$FILE_NAME ] |
63 |
then |
64 |
/bin/rm $DIR_CRON$FILE_NAME |
65 |
if [ $? -eq 0 ] |
66 |
then |
67 |
echo "*** Suppression du fichier de cron $DIR_CRON$FILE_NAME [OK]" |
68 |
break |
69 |
else |
70 |
echo "/!\\ Suppression du fichier de cron $DIR_CRON$FILE_NAME /!\\" |
71 |
exit |
72 |
fi |
73 |
else |
74 |
echo "*** Le fichier cron $DIR_CRON$FILE_NAME n'existe pas" |
75 |
break |
76 |
fi |
77 |
fi |
78 |
fi |
79 |
echo "*** Nom du volume pour desactiver les snapshot :" |
80 |
done |
81 |
exit 0 |
82 |
} |
83 |
|
84 |
while getopts "iN:h" OPTION |
85 |
do |
86 |
case $OPTION in |
87 |
h) |
88 |
usage |
89 |
exit 1 |
90 |
;; |
91 |
i) |
92 |
interactive |
93 |
;; |
94 |
N) |
95 |
NAMEZFS=$OPTARG |
96 |
;; |
97 |
*) |
98 |
usage |
99 |
exit 1 |
100 |
;; |
101 |
esac |
102 |
done |
103 |
if [[ -z $NAMEZFS ]] |
104 |
then |
105 |
usage |
106 |
exit 1 |
107 |
fi |
108 |
nointeractive |