Statistiques
| Révision :

root / bin / disable-snapshot @ 39

Historique | Voir | Annoter | Télécharger (2,44 ko)

1
#!/bin/bash
2
# $Id: disable-snapshot 39 2013-10-08 12:46:21Z ltaulell $
3

    
4
DIR_CRON="/etc/cron.d/"
5
DIR_CONF_SNAPSHOT="/opt/gZFS/snapshots/"
6
BIN_ZFS_SNAPSHOT="/sbin/zfs-snapshot"
7

    
8

    
9

    
10

    
11

    
12

    
13
function usage {
14
  echo "Usage :" 1>&2
15
  echo "disable-snapshot [OPTIONS]" 1>&2
16
  echo " -h display this message" 1>&2
17
  echo " -i interactive mode" 1>&2
18
  echo " -N Specify the name ZFS Volume/Filesystem" 1>&2
19

    
20
}
21

    
22
function nointeractive {
23
FILE_NAME=$(echo "snapshot-"${NAMEZFS//\//-})
24
   /bin/rm -f $DIR_CONF_SNAPSHOT$FILE_NAME.conf
25
   if [ -e $DIR_CONF_SNAPSHOT$FILE_NAME.conf ]
26
   then
27
      echo "Error : cannot delete $DIR_CONF_SNAPSHOT$FILE_NAME.conf"    
28
   fi
29

    
30
   /bin/rm $DIR_CRON$FILE_NAME
31
   if [ -e $DIR_CRON$FILE_NAME ]
32
   then
33
      echo "Error : cannot delete $DIR_CRON$FILE_NAME"
34
   fi
35

    
36
}
37

    
38
function interactive {
39

    
40
/sbin/zfs list
41
echo "*** Nom du volume pour desactiver les snapshot :"
42
while read inputline
43
do
44
   if [ "$inputline" != "" ]
45
   then  
46
       /sbin/zfs list $inputline
47
      if [ $? -eq 0 ]
48
      then
49
         FILE_NAME=$(echo "snapshot-"${inputline//\//-})
50
         if [ -e $DIR_CONF_SNAPSHOT$FILE_NAME.conf ]
51
         then
52
            /bin/rm -f $DIR_CONF_SNAPSHOT$FILE_NAME.conf
53
            if [ $? -eq 0 ]
54
            then
55
               echo "*** Suppression du fichier conf $DIR_CONF_SNAPSHOT$FILE_NAME.conf [OK]"
56
            else
57
               echo "/!\\ Suppression du fichier $DIR_CONF_SNAPSHOT$FILE_NAME.conf [ERROR] /!\\"
58
               exit
59
            fi
60
         else
61
            echo "*** Le fichier de conf $DIR_CONF_SNAPSHOT$FILE_NAME.conf n'existe pas"
62
         fi
63

    
64
         if [ -e $DIR_CRON$FILE_NAME ]
65
         then
66
            /bin/rm $DIR_CRON$FILE_NAME
67
            if [ $? -eq 0 ]
68
            then
69
               echo "*** Suppression du fichier de cron $DIR_CRON$FILE_NAME [OK]"
70
               break
71
            else
72
               echo "/!\\ Suppression du fichier de cron $DIR_CRON$FILE_NAME /!\\"
73
               exit
74
            fi
75
         else
76
            echo "*** Le fichier cron $DIR_CRON$FILE_NAME n'existe pas"
77
            break
78
         fi
79
      fi
80
   fi
81
   echo "*** Nom du volume pour desactiver les snapshot :"
82
done
83
exit 0
84
}
85

    
86
while getopts "iN:h" OPTION
87
do
88
     case $OPTION in
89
         h)
90
             usage
91
             exit 1
92
             ;;
93
         i)
94
             interactive
95
             ;;
96
         N)
97
             NAMEZFS=$OPTARG
98
             ;;
99
         *)
100
             usage
101
             exit 1
102
             ;;
103
     esac
104
done
105
if [[ -z $NAMEZFS ]]
106
then
107
     usage
108
     exit 1
109
fi
110
nointeractive