source: client/shared/scripts/cloneRemoteFromMaster @ b3dfeb6

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 b3dfeb6 was 8c10b3d, checked in by adv <adv@…>, 6 years ago

#851 cloneRemoteFromMaster define mcast client session as
port:MASTERIP:0:0

  • Property mode set to 100755
File size: 14.2 KB
Line 
1#!/bin/bash
2
3#/**
4#         cloneremoteFromMaster
5#@brief   Restaura una particion o imagen sobre las particiones de equipos cliente remotos
6#@param 1 str_origen admite dirección IP del equipo Master.
7#@param 2 str_origen  admite int_disk    str_REPO|str_CACHE
8#@param 3 str_origen  admite int partorigen   stre_imagen
9#@param 4 str_sesion multicast|unicast
10#@param $5 int_disco_destino
11#@param $6 init_particion_destino
12#@param $7 str_tool_clone
13#@param $8 str_tool_compresor
14#@param ejemplo: cloneRemoteFromMaster 172.17.36.11 1 1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop
15#@param ejemplo: cloneRemoteFromMaster 172.17.36.11 REPO /imagen1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop
16#@param ejemplo: cloneRemoteFromMaster 172.17.36.11 CACHE /imagen1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop
17#@return 
18#@exception OG_ERR_FORMAT     formato incorrecto.
19#@exception $OG_ERR_IMGSIZEPARTITION=30   #Imagen demasiado pequeña para ser clonada
20#@exception OG_ERR_REDUCEFS=17     #error al reducir sistema de archivos.
21#@exception OG_ERR_EXTENDFS=18     #errror al expandir el sistema de archivos.
22#@exception OG_ERR_UCASTSYNTAXT=50  # Error en la generación de sintaxis de transferenica unicast
23#@exception OG_ERR_UCASTSENDPARTITION=51  # Error en envio UNICAST de una particion
24#@exception OG_ERR_UCASTSENDFILE=52  # Error en envio UNICAST de un fichero
25#@exception OG_ERR_UCASTRECEIVERPARTITION=53  #Error en la recepcion UNICAST de una particion
26#@exception OG_ERR_UCASTRECEIVERFILE=54  #Error en la recepcion UNICAST de un fichero
27#@exception OG_ERR_MCASTSYNTAXT=55 # Error en la generacion de sintaxis de transferenica Multicast.
28#@exception OG_ERR_MCASTSENDFILE=56  # Error en envio MULTICAST de un fichero
29#@exception OG_ERR_MCASTRECEIVERFILE=57  #Error en la recepcion MULTICAST de un fichero
30#@exception OG_ERR_MCASTSENDPARTITION=58  # Error en envio MULTICAST de una particion
31#@exception OG_ERR_MCASTRECEIVERPARTITION=59  # Error en la recepcion MULTICAST de una particion
32#@exception OG_ERR_PROTOCOLJOINMASTER=60 # Error en la conexion de una sesion UNICAST|MULTICAST con el MASTER
33#@note   
34#@todo:
35#@version 0.9.1 - integración con OpenGnsys
36#@author  Antonio J. Doblas Viso. Universidad de Malaga.
37#@date   2009/03/17
38#@version 0.9.2 - adaptacion a OpenGnsys
39#@author  Antonio J. Doblas Viso. Universidad de Malaga.
40#@date    2010/07/27
41#@version 0.1.0 - gestion unicast
42#@author  Antonio J. Doblas Viso. Universidad de Malaga.
43#@date    2011/01/26
44#@version 1.0 - control de errores para el ogAdmServer
45#@author  Antonio J. Doblas Viso. Universidad de Malaga.
46#@date    2011/04/24
47#@version 1.0 - Uso de parted para controlar tamaño particion destino. Requiere Formateo FS previo -parted usa FS para el tamanyo".
48#@author  Antonio J. Doblas Viso. Universidad de Malaga.
49#@date    2011/04/24
50#@version 1.0.1 - Se elimina la operación de reducir la particion.
51#@author  Antonio J. Doblas Viso. Universidad de Malaga.
52#@date    2011/05/16
53#@version 1.0.3 - se integra con httpd-log.
54#@version 1.0.3 - Habilita el uso de la variable OGWINREDUCE=TRUE|TRUE para reducir el sistema de archivos a enviar
55#@author  Antonio J. Doblas Viso. Universidad de Malaga.
56#@date    2011/12/22
57#@version 1.0.6 - Uso de la funcion ogExecuteAndLog
58#@author  Antonio J. Doblas Viso. Universidad de Malaga.
59#@date    2012/02/12
60#@version 1.1.0.a - sesion multicast cliente puerto:master:0:0 (ticket #872)
61#@author  Antonio J. Doblas Viso
62#@date    2018/09/11
63#*/ ##
64#*/ ##
65
66#test 1. cliente sin particiones.    Detectado  TODO: crear estrucutras de particiones
67#test 2. cliente con particion mas pequeña. Detectado.
68#test 3. cleinte con particion destinio no formateado.  Detectado.
69#test 4. cliente con particion destino ocupado por el usuario pwd .  FALLO.
70#test 5. master sin origen particion.
71#test 6. master sin origen fichero.
72
73TIME1=$SECONDS
74PROG="$(basename $0)"
75
76trap "pkill faucet; exit 1" 0 1 2 3 6 9 14 15
77
78#AYUDA
79if [ $# -lt 1 -o "$1" == "help" ]; then
80        echo "cloneRemoteFromMaster ipmaster disk init [MULTICAST|UNICAST] session disk part tool comp"
81        exit 1
82fi
83
84#ERROR
85if [ $# -lt 6 ]; then
86    ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ipMaster SOURCE_disco SOURCE_particion [MULTICAST|UNICAST] SESSION TARGET_disk TARGET_partition"
87    exit $?
88fi
89
90#Load engine configurator from engine.cfg file.
91#Carga el configurador del engine desde el fichero engine.cfg
92# Valores por defecto: #IMGPROG="partclone" ; #IMGCOMP="lzop" ; #IMGEXT="img" #IMGREDUCE="TRUE"
93[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
94
95# Clear temporary file used as log track by httpdlog
96# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
97echo " " > $OGLOGCOMMAND
98
99ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*"
100
101# Procesar parámetros de entrada
102HOSTIP=`ogGetIpAddress`
103if [ -z "$HOSTIP" ]
104then
105        source /tmp/net-eth*
106        HOSTIP=`ogGetIpAddress`
107fi
108MASTERIP="$1"
109PROTOCOL="$4"
110case "${PROTOCOL^^}" in
111        MULTICAST)
112                SESSIONMCASTSERVER=$5
113                SESSIONMCASTCLIENT=`echo $5 | awk -F: '{print $1}'`:$MASTERIP:0:0
114        ;;
115        UNICAST)
116                SESSIONUCASTSERVER=$5
117                SESSIONUCASTCLIENT=`echo $5 | awk -F: '{print $1}'`:$MASTERIP
118        ;;
119        *)
120                exit $(ogRaiseError $OG_ERR_FORMAT "Protocolo $PROTOCOL no soportado en esta operacion"; echo $?)
121;;
122esac
123# contenedor destino (disco particion)
124DISKTARGET="$6"
125PARTTARGET="$7"
126#herramienta de compresión.
127TOOLCLONE="$8"
128COMPRESOR="$9"
129
130pkill faucet
131
132# Preparando Instrucción según sea Master o Client
133case $MASTERIP in
134        $HOSTIP)
135                ogEcho log session  "[1] Equipo Master preparando el origen de los datos a enviar"
136                ogGetPath $2 $3.img &>/dev/null; RC=$?;
137                ogDiskToDev $2 $3 &>/dev/null; RETVAL=$?;
138
139                if [ "$RC" == "0" ]; then
140                        IMG=$(ogGetPath $2 $3.img); MODEMASTER=SENDFILE
141                elif [ "$RETVAL" == "0" ]; then
142                        DISKSOURCE=$2; PARTSOURCE=$3; MODEMASTER=SENDPARTITION
143                else
144                        ogRaiseError $OG_ERR_NOTFOUND "$2 $3"; exit $?
145                fi
146                echo $MODEMASTER
147                # Preparando instrucción del Master segun $MODEMASTER{SENDPARTITION SENDFILE}                                   
148                case "$MODEMASTER" in
149                        SENDPARTITION)
150                                ogEcho log session "[5] Master en modo $MODEMASTER: informacion inicial a los clientes-slaves"
151                                if ps aux | grep -v grep | grep "faucet 4000"
152                                then
153                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 118"; exit $?     
154                                else
155                                        faucet 4000 --out echo "WORKING" &     
156                                fi                             
157                                ogEcho log session "[10]: Desmontando DISK:$DISKSOURCE PARTITION:$PARTSOURCE"
158                                ogUnmount $2 $3 ||  exit $(ogRaiseError $OG_ERR_LOCKED "no se puede desmontar $2 $3  l124"; echo $?)
159                                #Obtener tamaño de la partición.
160                                SIZE=$(ogGetPartitionSize $2 $3)  || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al detectar tamaño partcion $2 $3  l127"; echo $?)
161                               
162                                if [ "$OGWINREDUCE" == "TRUE" ]
163                                then
164                                        ogEcho log session "[15]: Calculando la reduccion del sistema de archivos DISK:$DISKSOURCE PARTITION:$PARTSOURCE SIZE:$SIZE"
165                                        ogReduceFs $2 $3 || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al reducir el FS $2 $3  l129"; echo $?)
166                                fi
167                                       
168                                REDSIZE=$(ogGetFsSize $2 $3) || exit $(ogRaiseError $OG_ERR_REDUCEFS "Error al detectar el nuevo FS $2 $3  l130"; echo $?)     
169                                TIMEAUX=$[SECONDS-TIME1]
170                                ogEcho log session "[20]: Preparada para enviar el sistema de archivos: Tamaño datos: $REDSIZE  origne: $DISKSOURCE $PARTSOURCE"
171                                ogEcho log session "      tiempo de reducción del sistema de archivos: $[TIMEAUX/60]m $[TIMEAUX%60]s"
172                               
173                                #if [ $REDSIZE -lt $SIZE ]; then
174                        #               echo "[24] Redimensionar partición a $REDSIZE KB."
175                        #               ogSetPartitionSize $2 $3 $REDSIZE
176                                #fi
177
178                                ogEcho log session "[25] Master en Modo $MODEMASTER: informacion de transferencia a los clientes-slaves $PROTOCOL $TOOLCLONE $COMPRESOR $REDSIZE"
179                                pkill faucet
180                                if ps aux | grep -v grep | grep "faucet 4000"
181                                then
182                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 140"; exit $?     
183                                else
184                                        faucet 4000 --out echo "READY $TOOLCLONE $COMPRESOR $REDSIZE" &
185                                fi
186                                case "${PROTOCOL^^}" in
187                                        MULTICAST)
188                                                ogEcho log session "[29] Transferencia Multicast: ogMcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONMCASTSERVER $TOOLCLONE $COMPRESOR "
189                                                ogExecAndLog session "ogMcastSendPartition" "$DISKSOURCE" "$PARTSOURCE" "$SESSIONMCASTSERVER" "$TOOLCLONE" "$COMPRESOR" || RETVAL=$?
190                                        ;;
191                                        UNICAST)
192                                                sleep 60
193                                                ogEcho log session "[29] Transferencia Unicast: ogUcastSendPartition $DISKSOURCE $PARTSOURCE $SESSIONUCASTSERVER $TOOLCLONE $COMPRESOR"
194                                                ogExecAndLog session "ogUcastSendPartition" "$DISKSOURCE" "$PARTSOURCE" "$SESSIONUCASTSERVER" "$TOOLCLONE" "$COMPRESOR" || RETVAL=$?
195                                        ;;
196                                esac
197                               
198                                #if [ $REDSIZE -lt $SIZE ]; then
199                                #       echo "[85] Redimensionar partición a $SIZE KB."
200                                #       ogSetPartitionSize $2 $3 $SIZE
201                                        ogEcho log session "[90] Extender sistema de archivos."
202                                        ogExtendFs $2 $3
203                                #fi
204                                pkill faucet
205                                if [ $RETVAL == 0 ]
206                                then
207                                        exit 0
208                                else
209                                    exit $(ogRaiseError $OG_ERR_MCASTSENDPARTITION "Error al enviar la particion  $2 $3 con protocolo $PROTOCOL l167"; echo $?)
210                                fi
211
212                        ;;
213                        SENDFILE)                               
214                                ogEcho log session "[5] Master en modo  $MODEMASTER: informacion inicial a los clientes-slaves"
215                                ogEcho log session "[10]: Preparando Imagen: $IMG"
216                                TOOLCLONE=$(ogGetImageProgram $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "TOOLCLONE no detectado l174"; echo $?)
217                                COMPRESOR=$(ogGetImageCompressor $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "COMPRESOR NO DETECTADO l175"; echo $?)
218                                REDSIZE=$(ogGetImageSize $2 $3) || exit $(ogRaiseError $OG_ERR_LOCKED "REDSIZE NO DETECTADO l176"; echo $?)
219                                ogEcho log session "[25] Master en Modo $MODEMASTER"
220                                ogEcho log "Informacion de transferencia a los clientes-slaves $PROTOCOL $TOOLCLONE $COMPRESOR $REDSIZE"
221                                if ps aux | grep -v grep | grep "faucet 4000"
222                                then
223                                        ogRaiseError $OG_ERR_NOTFOUND "MASTER: puerto en uso: 140"; exit $?     
224                                else
225                                        faucet 4000 --out echo "READY $TOOLCLONE $COMPRESOR $REDSIZE" &
226                                fi
227                                case "${PROTOCOL^^}" in
228                                        MULTICAST)
229                                                echo "[29] ogMcastSendFile $2 $3.img $SESSIONMCASTSERVER "
230                                                ogMcastSendFile  $2 $3.img $SESSIONMCASTSERVER  || RETVAL=$?
231                                                ;;
232                                        UNICAST)
233                                                sleep 60
234                                                echo "[29] ogUcastSendFile $2 $3.img $SESSIONUCASTSERVER"
235                                                ogUcastSendFile $2 $3.img $SESSIONUCASTSERVER || RETVAL=$?
236                                        ;;
237                                esac                                                   
238                                pkill faucet   
239                                if [ $RETVAL == 0 ]
240                                then
241                                        exit 0
242                                else
243                                        exit $(ogRaiseError $OG_ERR_MCASTSENDFILE "Error al enviar la image $2 $3.img con protocolo $PROTOCOL l200"; echo $?)
244                                fi
245                        ;;
246                esac
247                # FIN Preparando instrucción del Master segun $MODEMASTER{SENDPARTITION SENDFILE}
248        ;;
249        *)     
250                ogEcho log session "[1] Equipo -Client- preparando para recibir datos $PROTOCOL"
251                ogDiskToDev $DISKTARGET $PARTTARGET &>/dev/null || exit $(ogRaiseError $OG_ERR_LOCKED "El cliente no tiene esas particiones $DISKTARGET $PARTTARGET l211"; echo $?)     
252                # TODO: si el cliente no está en la lista de clientes UNICAST salir.
253                case "${PROTOCOL^^}" in
254                        UNICAST)
255                                echo "$SESSIONUCASTSERVER" | grep $HOSTIP || exit $(ogRaiseError $OG_ERR_PROTOCOLJOINMASTER "Este cliente no pertence a la sesion UNICAST l214"; echo $?)
256                        ;;
257                esac   
258                ogEcho log session "[2] Desmontando particion destino"
259                ogUnmount $DISKTARGET $PARTTARGET || exit $(ogRaiseError $OG_ERR_LOCKED "no se puede desmontar la particion destino $2 $3  l218"; echo $?)
260                ogEcho log session  "[25] Buscando informacion extra sobre la clonacion con el master $MASTERIP: "
261                sleep 10
262                TIMEWAITMASTER=120
263                TIMEWAITING=0
264                GETINFO="NONE"
265                while [ "${GETINFO}" != "OK" ]
266                do
267                        INFOEXTRA=`hose $MASTERIP 4000 --in cat 2>/dev/null`
268                        sleep 10; echo -n "."
269                        #echo comienza el timeout $TIMEWAITMASTER para abortar
270                        [ -z "$INFOEXTRA" ] && let TIMEWAITMASTER=$TIMEWAITMASTER-10
271                        [ "$TIMEWAITMASTER" -gt "0" ] || exit $(ogRaiseError $OG_ERR_PROTOCOLJOINMASTER " l230 "; echo $?)
272                        #Si primer parametro desde el server es READY, salimos del bucle
273                        GETINFO=$(echo $INFOEXTRA | awk '{print $1}')
274                        [ "$GETINFO" == "READY" ] && GETINFO="OK"
275                done           
276                echo $INFOEXTRA
277                TOOLCLONE=$(echo $INFOEXTRA | awk '{print $2}')
278                COMPRESOR=$(echo $INFOEXTRA | awk '{print $3}')
279                SIZEIMAGE=$(echo $INFOEXTRA | awk '{print $4}')
280                ogEcho log "$INFOEXTRA = herramienta= $TOOLCLONE  compresor= $COMPRESOR size= $SIZEIMAGE"
281                ogMount $DISKTARGET $PARTTARGET || ogFormat $DISKTARGET $PARTTARGET
282                #SIZEPARTTARGET=$(parted `ogDiskToDev $DISKTARGET $PARTTARGET` unit kB print | grep Disk | awk -F" " '{print $3}' | tr -d kB);
283                SIZEPARTTARGET=$(ogGetPartitionSize $DISKTARGET $PARTTARGET )
284                ogEcho log session  "[28] comprobando que el tamaño de la imagen $SIZEIMAGE es menor que el de la particion destino $SIZEPARTTARGET"
285                # comprobamos que el tamaño de a imagen es menor que la del cliente.
286                if [ "$SIZEIMAGE" -lt "$SIZEPARTTARGET" ]
287                then                           
288                        ogEcho log session "[30] Iniciando Cliente $PROTOCOL "
289                                case "${PROTOCOL^^}" in
290                                        MULTICAST)
291                                                ogEcho log session  "ogMcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONMCASTCLIENT $TOOLCLONE $COMPRESOR"
292                                                ogExecAndLog command "ogMcastReceiverPartition" "$DISKTARGET" "$PARTTARGET" "$SESSIONMCASTCLIENT" "$TOOLCLONE" "$COMPRESOR"  || exit $(ogRaiseError $OG_ERR_MCASTRECEIVERPARTITION " l251 "; echo $?)
293                                        ;;
294                                        UNICAST)
295                                                ogEcho log session "ogUcastReceiverPartition $DISKTARGET $PARTTARGET $SESSIONUCASTCLIENT $TOOLCLONE $COMPRESOR"
296                                                ogExecAndLog command "ogUcastReceiverPartition" "$DISKTARGET" "$PARTTARGET" "$SESSIONUCASTCLIENT" "$TOOLCLONE" "$COMPRESOR" || exit $(ogRaiseError $OG_ERR_UCASTRECEIVERPARTITION " l230 "; echo $?)
297                                        ;;
298                                esac                                           
299                        if which configureOsCustom &>/dev/null; then
300                                ogEcho log session "[90] configureOsCustom $DISKTARGET $PARTTARGET"
301                                # Si $2 = num_disk las varibles REPO IMGNAME estan vacias
302                                ! [[  $2 =~ ^[0-9]+$ ]] && REPO="$2" && IMGNAME="$3"
303                                configureOsCustom $DISKTARGET $PARTTARGET $REPO $IMGNAME
304                        else
305                                ogEcho log session "[90] $MSG_SCRIPTS_OS_CONFIGURE $DISKTARGET $PARTTARGET"
306                                configureOs $DISKTARGET $PARTTARGET                     
307                        fi
308
309                else
310                    # Si el tamaño de los datos recibidos es más grande que la particion destino
311                        ogRaiseError $OG_ERR_IMGSIZEPARTITION "ERROR tamanio particion= $SIZEPARTTARGET  menor que la imagen= $SIZEIMAGE"; exit $?
312                fi
313        ;;
314esac
315TIME=$[SECONDS-TIME1]
316ogEcho log session "[100] Duración de la operación $[TIME/60]m $[TIME%60]s"
317
Note: See TracBrowser for help on using the repository browser.