source: client/shared/scripts/ogRestaurarSoftIncremental @ 3dd7b5d

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 3dd7b5d was 8e2e266, checked in by alonso <alonso@…>, 12 years ago

Modificaciones para optimazación de la sincronización

git-svn-id: https://opengnsys.es/svn/branches/version1.0@3664 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 6.6 KB
Line 
1#!/bin/bash
2#___________________________________________________________________
3#
4#  RESTAURAR IMAGEN INCREMENTAL
5#___________________________________________________________________
6#
7# Parámetros recibidos desde el cliente:
8#
9# $1 Número de disco
10# $2 Número de particion
11# $3 Nombre canónico de la imagen básica (sin extensión)
12# $4 Dirección del repositorio
13# $5 Nombre canónico del software incremental (sin extensión)
14# $5 Es una cadena "nnnn" tipo flags que codifica varios parametros.
15#               Tiene el formato "nnnn" donde "n" vale 0 ó 1.   
16#               1XXX: Borrar la particion de destino antes de restaurar la imagen incremental
17#               X1XX: Copiar Imagen incremental también a la cache
18#               XX1X: Borrar previamente la imagen incremental de la cache antes de copiarla
19#               XXX1: No borrar archivos en destino
20#               El valor X indica que no importa el valor que tenga el dato
21# $7 Método de clonación 0=Desde caché 1=Desde repositorio
22# $8 Ruta de origen de la Imagen (Carpeta)
23#___________________________________________________________________
24#
25# Control parámetros
26#___________________________________________________________________
27
28        PROG="$(basename $0)"
29        if [ $# -lt 6 ]; then
30                usage=" ndisco nparticion nombre_imagen_basica ip_repositorio copiar_a_caché "
31                usage="$usage Borrar_cache_previamente metodo_clonación Ruta_origen"
32                ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG $usage"
33                exit $?
34        fi
35       
36        DISCO=$1
37        NPART=$2
38        NOMBREIMG=$3
39        IPREPOSITORIO=$4
40        NOMBREIMGINC=$5
41       
42        flag=$6
43        echo "flah:$flag">/tmp/log
44        BORRARIMG=${flag:0:1}
45        COPIACACHE=${flag:1:1}
46        BORRACACHE=${flag:2:1}
47        NOBORRACHIVOS=${flag:3:1}
48       
49        METCLONA=$7
50        RUTAORIGEN=$8
51#___________________________________________________________________
52#
53# Variables y configuración logs
54#___________________________________________________________________
55       
56        source /opt/opengnsys/scripts/ImagenesSincronizadas.lib
57
58#___________________________________________________________________
59#
60# Activa navegador para ver progreso
61#___________________________________________________________________
62
63        coproc /opt/opengnsys/bin/browser -qws http://localhost/cgi-bin/httpd-log.sh
64#___________________________________________________________________
65#
66# Proceso
67#___________________________________________________________________
68
69        echo "Restauracion de imagen incremental..." | tee -a $OGLOGSESSION $OGLOGFILE
70       
71        # Borrado previo de la partición
72        if [ $BORRARIMG -eq 1 ]; then
73                if [ -n $RUTAORIGEN ]; then
74                        echo "Borrando carpeta $PARTICION$RUTAORIGEN" | tee -a $OGLOGSESSION $OGLOGFILE
75                    rm -R $PARTICION$RUTAORIGEN         
76                else
77                        echo "Formateando la particion" | tee -a $OGLOGSESSION $OGLOGFILE
78                        ogFormat $DISCO $PARTICION $TIPOPARTICION
79                        RETVAL=$?       
80                        if [ $RETVAL -ne 0 ]; then
81                                 kill $COPROC_PID
82                           exit $OG_ERR_PARTITION
83                        fi
84                fi         
85        fi
86
87        # Sincronización desde repositorio
88        if [ $METCLONA = 1 ]; then
89                if [ $COPIACACHE = 0 ]; then   
90                        echo "Restaurando imagen basica desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
91                        ORIGEN="$REPOSITORIO/$NOMBREIMG/"       
92                        DESTINO=$PARTICION$RUTAORIGEN/ 
93                        # Restauración de la imagen básica
94                        echo "Sincronizando imagen basica entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
95                        restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1
96                        RETVAL=$?
97                        if [ $RETVAL -ne 0 ]; then
98                                 kill $COPROC_PID
99                           exit $OG_ERR_IMAGE
100                        fi
101
102                        # Restauración de la imagen incremental
103                        echo "Restaurando imagen incremental desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
104                        ORIGEN="$REPOSITORIO/$NOMBREIMGINC/"   
105                        DESTINO=$PARTICION$RUTAORIGEN/ 
106                        OP_DELETE=""
107                        # Restauración de la imagen incremental
108                        echo "Sincronizando imagen entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
109                        restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1
110                        restauraListaAcl $ORIGEN $DESTINO $SISTEMAFICHERO $DISCO $NPART
111                        RETVAL=$?
112                        kill $COPROC_PID
113                        echo "!!! Finaliza correctamente !!! la restauracion de imagen incremental $NOMBREIMGINC desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
114                        exit $RETVAL
115                fi             
116        fi     
117       
118        # Restauración desde la caché
119        echo "Restaurando desde la cache" | tee -a $OGLOGSESSION $OGLOGFILE
120       
121        # Comprobar si existe caché
122        CACHE=$(montaCache)
123        if [ -z $CACHE ]; then
124                echo "No se ha podido restaurar la imagen desde la cache" | tee -a $OGLOGSESSION $OGLOGFILE
125        ogRaiseError $OG_ERR_NOTCACHE "CACHE"
126                                kill $COPROC_PID
127        exit $?
128        fi                     
129
130        # Borrar imagen de la caché
131        if [ $BORRACACHE -eq 1 ]; then
132                echo "Borrando imagen basica $NOMBREIMG de la cache" | tee -a $OGLOGSESSION $OGLOGFILE
133            rm -R $CACHE$OGIMG/$NOMBREIMG
134                echo "Borrando imagen incremental $NOMBREIMGINC de la cache" | tee -a $OGLOGSESSION $OGLOGFILE
135            rm -R $CACHE$OGIMG/$NOMBREIMGINC
136        fi
137       
138        # Actualización de la caché
139        echo "Actualizando cache local desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
140       
141        ORIGEN="$REPOSITORIO/$NOMBREIMG/"
142        DESTINO="$CACHE$OGIMG/$NOMBREIMG/"
143        echo "Sincronizando imagen basica entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
144        restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1     
145        RETVAL=$?       
146        if [ $RETVAL -ne 0 ]; then
147                 kill $COPROC_PID
148           exit $OG_ERR_IMAGE
149        fi                     
150        ORIGEN="$REPOSITORIO/$NOMBREIMGINC/"
151        DESTINO="$CACHE$OGIMG/$NOMBREIMGINC/"
152        echo "Sincronizando imagen incremental entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
153        restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1     
154        RETVAL=$?       
155        if [ $RETVAL -ne 0 ]; then
156                 kill $COPROC_PID
157           exit $OG_ERR_IMAGE
158        fi     
159
160        # Restauración desde caché a la partición
161       
162        echo "Copiando imagen basica a la partición desde cache local" | tee -a $OGLOGSESSION $OGLOGFILE
163        ORIGEN="$CACHE$OGIMG/$NOMBREIMG/"
164        DESTINO=$PARTICION$RUTAORIGEN/ 
165        echo "Sincronizando imagen entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
166        restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 2     
167        RETVAL=$?       
168        if [ $RETVAL -ne 0 ]; then
169                 kill $COPROC_PID
170           exit $OG_ERR_IMAGE
171        fi
172       
173        echo "Copiando imagen incremental a la partición desde cache local" | tee -a $OGLOGSESSION $OGLOGFILE
174        ORIGEN="$CACHE$OGIMG/$NOMBREIMGINC/"
175        DESTINO=$PARTICION$RUTAORIGEN/ 
176        OP_DELETE=""
177        echo "Sincronizando imagen entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
178        restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 2     
179        restauraListaAcl $ORIGEN $DESTINO $SISTEMAFICHERO $DISCO $NPART
180        RETVAL=$?       
181        if [ $RETVAL -ne 0 ]; then
182                 kill $COPROC_PID
183           exit $OG_ERR_IMAGE
184        fi
185        echo "!!! Finaliza correctamente !!! restauracion imagen incremental $NOMBREIMGINC desde cache local" | tee -a $OGLOGSESSION $OGLOGFILE
186#___________________________________________________________________
187#
188# Retorno
189#___________________________________________________________________
190
191        kill $COPROC_PID
192
193        exit 0
Note: See TracBrowser for help on using the repository browser.