Statistics
| Revision:

root / bin / disable-snapshot @ 55

History | View | Annotate | Download (2.6 kB)

1
#!/bin/bash
2
# $Id: disable-snapshot 55 2013-10-10 16:20:06Z kreverch $
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
DIR_CRON="/etc/cron.d/"
9
DIR_CONF_SNAPSHOT="/opt/gZFS/snapshots/"
10
BIN_ZFS_SNAPSHOT="/sbin/zfs-snapshot"
11
BINZFS="/sbin/zfs"
12
BINZPOOL="/sbin/zpool"
13

    
14

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

    
22
}
23

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

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

    
38
}
39

    
40
function interactive {
41

    
42
$BINZFS list
43
echo "*** Enter a ZFS volume/filesystem name :"
44
while read inputline
45
do
46
   if [ "$inputline" != "" ]
47
   then  
48
       $BINZFS list $inputline
49
      if [ $? -eq 0 ]
50
      then
51
         FILE_NAME=$(echo "snapshot-"${inputline//\//-})
52
         if [ -e $DIR_CONF_SNAPSHOT$FILE_NAME.conf ]
53
         then
54
            /bin/rm -f $DIR_CONF_SNAPSHOT$FILE_NAME.conf
55
            if [ $? -eq 0 ]
56
            then
57
               echo "*** Remove the configuration file $DIR_CONF_SNAPSHOT$FILE_NAME.conf [OK]"
58
            else
59
               echo "/!\\ Remove the configuration file  $DIR_CONF_SNAPSHOT$FILE_NAME.conf [ERROR] /!\\"
60
               exit
61
            fi
62
         else
63
            echo "*** The configuration file $DIR_CONF_SNAPSHOT$FILE_NAME.conf does not exist"
64
         fi
65

    
66
         if [ -e $DIR_CRON$FILE_NAME ]
67
         then
68
            /bin/rm $DIR_CRON$FILE_NAME
69
            if [ $? -eq 0 ]
70
            then
71
               echo "*** Remove cron file $DIR_CRON$FILE_NAME [OK]"
72
               break
73
            else
74
               echo "/!\\ Remove cron file $DIR_CRON$FILE_NAME [ERROR] /!\\"
75
               exit
76
            fi
77
         else
78
            echo "*** The cron file $DIR_CRON$FILE_NAME does not exist"
79
            break
80
         fi
81
      fi
82
   fi
83
   echo "*** Enter a ZFS volume/filesystem name :"
84
done
85
exit 0
86
}
87

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