source: client/shared/scripts/restoreImage @ 46f7d6f

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 46f7d6f was 4fcbcc8, checked in by irina <irinagomez@…>, 11 years ago

#636 #537 Log en tiempo real. En los script de restauracion los mensajes se envian a session.log y las salidas de los comandos a commad.log. utf-8 en la pagina que muestra los log

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

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#!/bin/bash
2# Script de ejemplo para restaurar una imagen.
3# (puede usarse como base para el programa de restauración de imágenes usado por OpenGNSys Admin).
4
5TIME1=$SECONDS
6PROG="$(basename $0)"
7if [ $# -lt 4 ]; then
8    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
9    exit ${PIPESTATUS[0]}
10fi
11
12#Load engine configurator from engine.cfg file.
13#Carga el configurador del engine desde el fichero engine.cfg
14# Valores por defecto: #IMGPROG="partclone" ; #IMGCOMP="lzop" ; #IMGEXT="img" #IMGREDUCE="TRUE"
15[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
16
17# Clear temporary file used as log track by httpdlog
18# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
19echo " " > $OGLOGCOMMAND
20[ "$(ogGetCaller)" == "deployImage" ] || echo -n "" > $OGLOGSESSION;
21
22echo "[1] $MSG_SCRIPTS_START $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE
23
24# Procesar parámetros de entrada
25REPO="${1^^}"
26IMGNAME="$2"
27DISK="$3"
28PART="$4"
29PROTO="${5^^}"
30PROTO=${PROTO:-"UNICAST"}
31PROTOOPT="$6"
32IMGTYPE="${IMGTYPE:-"img"}"
33# Comprobar que existe la imagen del origen.
34IMGFILE=$(ogGetPath "$REPO" "$IMGNAME.$IMGTYPE")
35IMGDIR=$(ogGetParentPath "$REPO" "$IMGNAME")
36if [ "$IMGFILE" == "" -o "$IMGDIR" == "" ]; then
37        ogRaiseError $OG_ERR_NOTFOUND "$REPO, ${IMGNAME%/*}" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
38        exit ${PIPESTATUS[0]}
39fi
40
41# Procesar protocolos de transferencia.
42case "$PROTO" in
43    UNICAST|UNICAST-DIRECT)
44        # Restaurar la imagen.
45        echo "[40] ogRestoreImage $REPO $IMGNAME $DISK $PART UNICAST" | tee -a $OGLOGSESSION $OGLOGFILE
46        ogRestoreImage "$REPO" "$IMGNAME" "$DISK" "$PART" UNICAST 2>&1 | tee -a $OGLOGCOMMAND
47        RETVAL=${PIPESTATUS[0]}
48        ;;
49    MULTICAST|MULTICAST-DIRECT)
50        PORT=$(echo $PROTOOPT | cut -f1 -d":")
51        TOOL=$(ogGetImageProgram REPO $IMGNAME)
52        COMPRESS=$(ogGetImageCompressor REPO $IMGNAME)
53        #TODO comprobar parametros anteriores
54        echo "[40] ogMcastReceiverPartition $DISK $PART $PORT $TOOL $COMPRESS" | tee -a $OGLOGSESSION $OGLOGFILE
55        ogMcastRequest "$IMGNAME.img" "$PROTOOPT"
56        ogMcastReceiverPartition "$DISK" "$PART" "$PORT" "$TOOL" "$COMPRESS" 2>&1 | tee -a $OGLOGCOMMAND
57        RETVAL=${PIPESTATUS[0]}
58        ;;
59    *)  # Protocolo desconocido.
60        ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones ]" 2>&1 | tee -a $OGLOGSESSION $OGLOGFILE
61
62        exit $?
63esac
64
65TIME=$[SECONDS-TIME1]
66echo "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
67
68# Código de salida del comando prinicpal de restauración.
69exit $RETVAL
70
Note: See TracBrowser for help on using the repository browser.