source: client/shared/scripts/restoreImage @ e371a87

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-instalacion
Last change on this file since e371a87 was ce678a0, checked in by irina <irinagomez@…>, 8 years ago

#781 deploy con multicast: Si timeout para error multicast es menor que tiempo de espera del servidor lo aumento. ogAdmRepoAux: Se corrige errata al llamar a sendMcastFile

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

  • Property mode set to 100755
File size: 4.2 KB
RevLine 
[f8f4dfa]1#!/bin/bash
[fe6843b]2#/**
3#@file    restoreImage
4#@brief   Script de ejemplo para restaurar una imagen.
5#@param   $1 Repositorio (CACHE, REPO o dirección IP)
6#@param   $2 Nombre canónico de la imagen (sin extensión)
7#@param   $3 Número de disco
8#@param   $4 Número de particion
9#@param   $5 Protocolo (UNICAST, UNICAST-DIRECT, MULTICAST o MULTICAST-DIRECT)
10#@param   $6 Opciones del protocolo
11#@exception OG_ERR_FORMAT   1 formato incorrecto.
12#@exception OG_ERR_NOTFOUND  2 cambio de repositorio: repositorio no encontrado
13#@exception OG_ERR_NOTFOUND  2 fichero de imagen o partición no detectados.
[0dcf48a]14#@exception $OG_ERR_MCASTRECEIVERFILE  57 Error en la recepción Multicast de un fichero
15#@exception $OG_ERR_PROTOCOLJOINMASTER 60 Error en la conexión de una sesión Unicast|Multicast con el Master
[fe6843b]16#@version 1.1 - Cambio de repositorio para el recurso remoto images si es necesario
17#@author  Irina Gomez, ETSII Universidad de Sevilla
18#@date    2015-06-16
[0dcf48a]19#@version 1.1 - Control de errores en transferencia multicast (ticket #781)
20#@author  Irina Gomez, ETSII Universidad de Sevilla
21#@date    2017/04/20
[fe6843b]22#**/
[f8f4dfa]23
[f5432db7]24TIME1=$SECONDS
[f8f4dfa]25PROG="$(basename $0)"
[87a7a799]26if [ $# -lt 4 ]; then
[64cf3d3]27    ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]"
[30ad471]28    exit $?
[f8f4dfa]29fi
30
[d2f28cf]31#Load engine configurator from engine.cfg file.
32#Carga el configurador del engine desde el fichero engine.cfg
33# Valores por defecto: #IMGPROG="partclone" ; #IMGCOMP="lzop" ; #IMGEXT="img" #IMGREDUCE="TRUE"
34[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
35
36# Clear temporary file used as log track by httpdlog
37# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
[7f8d5d5]38echo " " > $OGLOGCOMMAND
[adbfa2a]39ogCheckStringInGroup "$(ogGetCaller)" "deployImage restoreImageCustom" || echo -n "" > $OGLOGSESSION;
[d2f28cf]40
[fe10bff]41ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*"
[d2f28cf]42
[f8f4dfa]43# Procesar parámetros de entrada
[d2f28cf]44REPO="${1^^}"
45IMGNAME="$2"
46DISK="$3"
47PART="$4"
48PROTO="${5^^}"
49PROTO=${PROTO:-"UNICAST"}
50PROTOOPT="$6"
[ce678a0]51# Si MCASTWAIT menos que tiempo de espera del servidor lo aumento
52if [ "${PROTO%-*}" == "MULTICAST" ] && [[ ${PROTOOPT##*:} =~ ^-?[0-9]+$ ]]; then
53    [ ${MCASTWAIT:-0} -lt ${PROTOOPT##*:} ] && let MCASTWAIT=${PROTOOPT##*:}+5
54fi
[d2f28cf]55IMGTYPE="${IMGTYPE:-"img"}"
[fe6843b]56
[dc157ae]57# Unidad organizativa
58[ "$ogunit" != "" ] && OGUNIT="$ogunit/"
59
[fe6843b]60# Si es una ip y es igual a la del equipo restaura desde cache
61[ "$REPO" == "$(ogGetIpAddress)" ] && REPO="CACHE"
62# Si es una ip y es distinta a la del recurso samba cambiamos de REPO.
63ogCheckIpAddress $REPO
64if [ $? == 0 -o $REPO == "REPO" ] ; then
65        # Si falla el cambio -> salimos con error repositorio no valido
[dc157ae]66        ogChangeRepo $REPO ${OGUNIT%/} || exit $(ogRaiseError $OG_ERR_NOTFOUND '$REPO $OGUNIT'; echo $?)
[fe6843b]67        REPO="REPO"
68fi
69
[d2f28cf]70# Comprobar que existe la imagen del origen.
[4fcbcc8]71IMGFILE=$(ogGetPath "$REPO" "$IMGNAME.$IMGTYPE")
72IMGDIR=$(ogGetParentPath "$REPO" "$IMGNAME")
73if [ "$IMGFILE" == "" -o "$IMGDIR" == "" ]; then
[64cf3d3]74        ogRaiseError session $OG_ERR_NOTFOUND "$REPO, ${IMGNAME%/*}"
[30ad471]75        exit $?
[4fcbcc8]76fi
[41d9755]77
[d2f28cf]78# Procesar protocolos de transferencia.
79case "$PROTO" in
80    UNICAST|UNICAST-DIRECT)
81        # Restaurar la imagen.
[e7e3140]82        ogEcho log session "[40] ogRestoreImage $REPO $IMGNAME $DISK $PART UNICAST"
[d32ebd8]83        ogExecAndLog command ogRestoreImage "$REPO" "$IMGNAME" "$DISK" "$PART"
84        RETVAL=$?
[d2f28cf]85        ;;
86    MULTICAST|MULTICAST-DIRECT)
87        PORT=$(echo $PROTOOPT | cut -f1 -d":")
88        TOOL=$(ogGetImageProgram REPO $IMGNAME)
89        COMPRESS=$(ogGetImageCompressor REPO $IMGNAME)
90        #TODO comprobar parametros anteriores
[e7e3140]91        ogEcho log session "[40] ogMcastReceiverPartition $DISK $PART $PORT $TOOL $COMPRESS"
[b3a5e02]92        ogMcastRequest "$IMGNAME.img" "$PROTOOPT" || exit $?
[9a1df17]93        ogExecAndLog command ogMcastReceiverPartition "$DISK" "$PART" "$PORT" "$TOOL" "$COMPRESS"
[1a2fa9d8]94        RETVAL=$?
[d2f28cf]95        ;;
96    *)  # Protocolo desconocido.
[64cf3d3]97        ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones ]"
[d2f28cf]98        exit $?
99esac
[b0ff94d]100
[f5432db7]101TIME=$[SECONDS-TIME1]
[e7e3140]102ogEcho log session "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s"
[f8f4dfa]103
[f9e03ad]104# Código de salida del comando prinicpal de restauración.
105exit $RETVAL
106
Note: See TracBrowser for help on using the repository browser.