Statistiques
| Révision :

root / bin / disable-snapshot @ 40

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

1
#!/bin/bash
2
# $Id: disable-snapshot 40 2013-10-08 14:37:55Z ltaulell $
3

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

    
8
# TODO: traduire les msg
9

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

    
17
}
18

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

    
27
   /bin/rm $DIR_CRON$FILE_NAME
28
   if [ -e $DIR_CRON$FILE_NAME ]
29
   then
30
      echo "Error : cannot delete $DIR_CRON$FILE_NAME"
31
   fi
32

    
33
}
34

    
35
function interactive {
36

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

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

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