source: client/shared/scripts/restoreImage @ b6c0607

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 b6c0607 was b3a5e02, checked in by irina <irinagomez@…>, 8 years ago

#678 ogMcastRequest: Se adaptan a unidades organizativas con directorios separados.

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

  • Property mode set to 100755
File size: 3.9 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"
51IMGTYPE="${IMGTYPE:-"img"}"
[fe6843b]52
[dc157ae]53# Unidad organizativa
54[ "$ogunit" != "" ] && OGUNIT="$ogunit/"
55
[fe6843b]56# Si es una ip y es igual a la del equipo restaura desde cache
57[ "$REPO" == "$(ogGetIpAddress)" ] && REPO="CACHE"
58# Si es una ip y es distinta a la del recurso samba cambiamos de REPO.
59ogCheckIpAddress $REPO
60if [ $? == 0 -o $REPO == "REPO" ] ; then
61        # Si falla el cambio -> salimos con error repositorio no valido
[dc157ae]62        ogChangeRepo $REPO ${OGUNIT%/} || exit $(ogRaiseError $OG_ERR_NOTFOUND '$REPO $OGUNIT'; echo $?)
[fe6843b]63        REPO="REPO"
64fi
65
[d2f28cf]66# Comprobar que existe la imagen del origen.
[4fcbcc8]67IMGFILE=$(ogGetPath "$REPO" "$IMGNAME.$IMGTYPE")
68IMGDIR=$(ogGetParentPath "$REPO" "$IMGNAME")
69if [ "$IMGFILE" == "" -o "$IMGDIR" == "" ]; then
[64cf3d3]70        ogRaiseError session $OG_ERR_NOTFOUND "$REPO, ${IMGNAME%/*}"
[30ad471]71        exit $?
[4fcbcc8]72fi
[41d9755]73
[d2f28cf]74# Procesar protocolos de transferencia.
75case "$PROTO" in
76    UNICAST|UNICAST-DIRECT)
77        # Restaurar la imagen.
[e7e3140]78        ogEcho log session "[40] ogRestoreImage $REPO $IMGNAME $DISK $PART UNICAST"
[d32ebd8]79        ogExecAndLog command ogRestoreImage "$REPO" "$IMGNAME" "$DISK" "$PART"
80        RETVAL=$?
[d2f28cf]81        ;;
82    MULTICAST|MULTICAST-DIRECT)
83        PORT=$(echo $PROTOOPT | cut -f1 -d":")
84        TOOL=$(ogGetImageProgram REPO $IMGNAME)
85        COMPRESS=$(ogGetImageCompressor REPO $IMGNAME)
86        #TODO comprobar parametros anteriores
[e7e3140]87        ogEcho log session "[40] ogMcastReceiverPartition $DISK $PART $PORT $TOOL $COMPRESS"
[b3a5e02]88        ogMcastRequest "$IMGNAME.img" "$PROTOOPT" || exit $?
[9a1df17]89        ogExecAndLog command ogMcastReceiverPartition "$DISK" "$PART" "$PORT" "$TOOL" "$COMPRESS"
[1a2fa9d8]90        RETVAL=$?
[d2f28cf]91        ;;
92    *)  # Protocolo desconocido.
[64cf3d3]93        ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones ]"
[d2f28cf]94        exit $?
95esac
[b0ff94d]96
[f5432db7]97TIME=$[SECONDS-TIME1]
[e7e3140]98ogEcho log session "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s"
[f8f4dfa]99
[f9e03ad]100# Código de salida del comando prinicpal de restauración.
101exit $RETVAL
102
Note: See TracBrowser for help on using the repository browser.