-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathing_borrar_db.sh
123 lines (109 loc) · 2.78 KB
/
ing_borrar_db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/ksh
# Funciona bien en Linux
# set -x
## Configuracion DB
validateDB=(wmosxdpr wmosxdhi)
validateFS=(AL DB)
## Asociar DB con Filesystem, tipo AL
typeset -A AL
AL["wmosxdpr"]=/u02/ORAARCH/wmosxdpr/
AL["wmosxdhi"]=/u02/ORAARCH/wmosxdhi/
## Asociar DB con Filesystem, tipo DB
typeset -A DB
DB["wmosxdpr"]=/backup/wmosxdpr/
DB["wmosxdhi"]=/backup/wmosxdhi/
###############################################################################
## INIT
USERDB=$1
USERFS=$2
USERDAY=$3
## FUNCIONS
## Muestra elementos de un arreglo
listArray(){
typeset -n array=$1
for i in ${array[@]}; do
if [ $i == ${array[0]} ]; then
printf "$i"
else
printf "|$i"
fi
done
}
## Verifica si existe string dentro de un arreglo
# containsElement "string" "array"
containsElement () {
typeset -n array=$2
for e in "${array[@]}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
## Valida Numero
validateNumber() {
if echo $1 | egrep -q '^[0-9]+$'; then
return 0
else
return 1
fi
}
## Function USAGE
usage(){
echo ""
printf " Usage:\n\n"
printf " execas ing_borra_bd (";listArray "validateDB"; printf ") (";listArray "validateFS";printf ") <dias>\n\n"
printf " Tipo de borrado (AL|DB):\n"
printf " AL: Archive Log\n"
printf " DB: Base de datos\n\n"
printf " NOTA: Se eliminaran archivos que hayan sufrido modificaciones hace más de <dias> dias\n"
echo ""
}
## Validaciones
## Validar cantidad de argumentos = 3
if [ ${#} -ne 3 ]; then
usage
exit 255
fi
## Validar nombre de DB, tipo filesystem
if ( (! containsElement ${USERDB} "validateDB") || (! containsElement ${USERFS} "validateFS") || (! validateNumber ${USERDAY}) );then
usage
## Validar DB
if ( ! containsElement ${USERDB} "validateDB" );then
printf " Favor Usar Base de datos: "; listArray "validateDB"; printf "\n"
fi
## Validar TipoFS
if ( ! containsElement ${USERFS} "validateFS" );then
printf " Favor Usar Filesystems: "; listArray "validateFS"; printf "\n"
fi
## Validar <dias>
if ( ! validateNumber ${USERDAY} );then
printf " Favor Usar <dias>: numeros\n\n"
fi
exit 10
fi
## Obtener PATH y PATRON
USERPATRON=""
USERPATH=""
if [ $USERFS == "AL" ];then
USERPATH=${AL[$USERDB]}
USERPATRON="log_*.arc"
elif [ $USERFS == "DB" ];then
USERPATH=${DB[$USERDB]}
USERPATRON="ARC*"
fi
## Main
echo ""
echo "Verificando datos"
echo " Base de datos: "$USERDB
echo " Tipo de Borrado: "$USERFS
echo " Dias de antiguedad: "$USERDAY
echo ""
echo "Está seguro que desea eliminar: " $USERPATH$USERPATRON" "
printf "Escriba (yes|Yes|y) :"
read answer
case $answer in
yes|Yes|y)
/usr/local/bin/delfilper.pl -dir=$USERPATH -patron=$USERPATRON -dias=$USERDAY
;;
*)
echo "No se ha eliminado nada"
exit 1
;;
esac