source: client/shared/scripts/createImage @ 6bb748b

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 6bb748b was 31d4f1a5, checked in by irina <irinagomez@…>, 7 years ago

#815 ogGetSizeParameters: Al calcular el espacio libre en el repositorio tiene en cuenta si la imagen ya existe.

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

  • Property mode set to 100755
File size: 7.1 KB
RevLine 
[f8f4dfa]1#!/bin/bash
[eb9424f]2
3#/**
[d2f28cf]4#@file    createImage
[eb9424f]5#@brief   Scirpt de ejemplo para crear una imagen de un sistema de archivos.
[5b825b50]6#@brief   Se usa como base para el programa de creación de imágenes de OpenGnsys Admin).
[eb9424f]7#@param 1 disco
8#@param 2 particion
9#@param 3 REPO|CACHE
10#@param 4 imagen
11#@return 
[2d40ba26]12#@exception OG_ERR_FORMAT     # 1 formato incorrecto.
13#@exception OG_ERR_PARTITION  # 3 Error en partición de disco o en su sistema de archivos
14#@exception OG_ERR_IMAGE      # 5 Error en funcion ogCreateImage o ogRestoreImage.
15#@exception OG_ERR_NOTWRITE   # 14 error de escritura
16#@exception OG_ERR_NOTCACHE   # 15 si cache no existe 15
17#@exception OG_ERR_CACHESIZE  # 16 si espacio de la cache local o remota no tiene espacio 16
18#@exception OG_ERR_REDUCEFS   # 17 error al reducir sistema de archivos.
19#@exception OG_ERR_EXTENDFS   # 18 Errror al expandir el sistema de archivos.
[eb9424f]20#@note   
[2d40ba26]21#@todo: que hacer, si el tamaño de la cache es sufciente, pero no tiene espacio libre
22#@todo: que hacer, si hay una imagen con igual nombre en la cache
[eb9424f]23#@version 1.0 - control de errores para el ogAdmServer
24#@author 
[2d40ba26]25#@date   2011-04-10
[c3758e7]26#@version 1.0.1 - Control de espacio requerido
27#@author  Antonio J.Doblas Viso
[2d40ba26]28#@date   2011-05-10
[79a4175]29#@version 1.0.2 - Separacion de log
[f311787]30#@author  Antonio J.Doblas Viso
31#@date   2011-08-4
[a6d6d6f]32#@version 1.1.0 - La copia de seguridad de la imagen antigua se hace después de las comprobaciones.
33#@author  Irina Gomez - ETSII Universidad de Sevilla
34#@date    2016-10-14
[e784187]35#@version 1.1.0 - Se muestra el espacio necesario para alojar la imagen y el disponible (ticket #771)
36#@author  Irina Gomez - ETSII Universidad de Sevilla
37#@date    2017-03-28
[eb9424f]38#*/ ##
39
[2d40ba26]40# Test 1.  crear una imagen en un REPO sin espacio libre.
41# test 2.  crear una imagen en un REPO en modo solo lectura.
42# test 3.  intentar crear una imagen en la cache de un equipo que no la disponga.
43# test 4.  crear una imagen en la Cache sin espacio sufiente.
44# test 5.  intentar crear una imagen, en la que no se puede reducir el FS.
[f8f4dfa]45
[f311787]46
[f8f4dfa]47PROG="$(basename $0)"
48if [ $# -ne 4 ]; then
[be85bb2]49    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen"
[f8f4dfa]50    exit $?
51fi
52
[d2f28cf]53TIME1=$SECONDS
54
55#Load engine configurator from engine.cfg file.
56#Carga el configurador del engine desde el fichero engine.cfg
57[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
58
[b92b4bb]59# Valores por defecto en etc/engine.cfg
60#IMGPROG="partclone"
61#IMGCOMP="lzop"
[b9797f2]62IMGEXT=${IMGEXT:-"img"}
[b92b4bb]63#IMGREDUCE="TRUE"
[4ceafc1]64REPO="${3^^}"
[95b340a]65
[79a4175]66# Unidad organizativa
67[ "$ogunit" != "" ] && OGUNIT="$ogunit"
68
[d2f28cf]69# Clear temporary file used as log track by httpdlog
70# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
[adbfa2a]71# salvo si es llamado desde createImageCustom
72if [ "$(ogGetCaller)" != "createImageCustom" ]; then
73    echo " " > $OGLOGSESSION; echo " " > $OGLOGCOMMAND; echo " " > ${OGLOGCOMMAND}.tmp
74fi
[f311787]75
[e7e3140]76ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*"
[f311787]77
[4ceafc1]78# Si es una ip y es igual a la del equipo restaura desde cache
79[ "$REPO" == "$(ogGetIpAddress)" ] && REPO="CACHE"
80# Si es una ip y es distinta a la del recurso samba cambiamos de REPO.
81ogCheckIpAddress $REPO
82if [ $? == 0 -o $REPO == "REPO" ] ; then
83        # Si falla el cambio -> salimos con error repositorio no valido
[79a4175]84        ogChangeRepo $REPO $OGUNIT || exit $(ogRaiseError $OG_ERR_NOTFOUND '$REPO'; echo $?)
[4ceafc1]85        REPO="REPO"
86fi
87
[defcdab]88# Si el repositorio es CACHE comprobamos que exista
[4ceafc1]89if [ "$REPO" == "CACHE" ]; then
[2d40ba26]90    ! ogFindCache >/dev/null && exit $(ogRaiseError $OG_ERR_NOTCACHE "CACHE "; echo $?)
[3aaf91d]91fi
[defcdab]92
[c40a6b4]93# Obtener información de los parámetros de entrada.
[2d40ba26]94PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError $OG_ERR_PARTITION "$1 $2"; echo $?)
95
96#Comprobamos acceso de escritura.
97DIRTEMP=$(date +%Y%m%d-%H%M%S)
[4ceafc1]98ogMakeDir $REPO /$4$DIRTEMP 2>/dev/null || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO"; echo $?) && ogDeleteTree $REPO /$4$DIRTEMP
[2d40ba26]99
[4ceafc1]100IMGDIR=$(ogGetParentPath "$REPO" "/$4")
[180a07dd]101# Si no existe, crear subdirectorio de la imagen.
102if [ $? != 0 ]; then
[4ceafc1]103    ogEcho log session "[5] $MSG_HELP_ogMakeDir \"$REPO $(dirname "$4")."
104    ogMakeDir "$REPO" $(dirname "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO /$4"; echo $?)
105    IMGDIR=$(ogGetParentPath "$REPO" "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO /$4"; echo $?)
[180a07dd]106fi
[95b340a]107IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT
[d2f28cf]108
[e272d9e]109echo " " > $OGLOGCOMMAND
[d3dc88d]110# Borramos ficheros de paginacion y configuracion
111ogCleanOs $1 $2
112
113#Comprobar espacio que requerira la imagen para ser almacenada
[31d4f1a5]114read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$REPO" "$4")
[d2f28cf]115
[e784187]116ogEcho log session "[16] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED $SIZEFREE"
[4ceafc1]117[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$REPO"; echo $?)
[2d40ba26]118
[3aaf91d]119# Comprobar consistencia del sistema de archivos.
[e272d9e]120echo " " > $OGLOGCOMMAND
121SIZEFS=$(ogGetFsSize  $1 $2)
[e7e3140]122ogEcho log session "[20] $MSG_HELP_ogCheckFs  $PART $SIZEFS (KB)"
[d2f28cf]123ogUnmount $1 $2 2>/dev/null
[2d40ba26]124ogCheckFs $1 $2 || exit $(ogRaiseError $OG_ERR_PARTITION "ogCheckFs $1 $2" && echo $?)
[914d834]125
[d2f28cf]126# Evaluar variable de engine.cfg para reducir el sistema de archivos en la creacion
127if [ "$IMGREDUCE" == "TRUE" ]
[b92b4bb]128then
[e7e3140]129    ogEcho log session "[30]: $MSG_HELP_ogReduceFs"
[d2f28cf]130    ogReduceFs $1 $2 &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; echo $?)
131    NEWSIZEFS=$(ogGetFsSize  $1 $2)
132    TIMEAUX=$[SECONDS-TIME1]
[e7e3140]133    ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL ( $NEWSIZEFS KB ) : $[TIMEAUX/60]m $[TIMEAUX%60]s"
[b92b4bb]134fi
[914d834]135
[a6d6d6f]136# Renombrar el fichero de imagen si ya existe.
137if [ -f "$IMGFILE" ]; then
138    ogEcho log session "[10] $MSG_SCRIPTS_FILE_RENAME \"$IMGFILE\" ->  \"$IMGFILE.ant\"."
139    mv "$IMGFILE" "$IMGFILE.ant"
140    mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null
141    mv "$IMGFILE.sum" "$IMGFILE.sum.ant" 2>/dev/null
142    mv "$IMGFILE.full.sum" "$IMGFILE.full.sum.ant" 2>/dev/null
143fi
144
[6d3f526]145# Crear la imagen.
[e272d9e]146echo " " > $OGLOGCOMMAND
147TIME2=$SECONDS
[4ceafc1]148ogEcho log session "[40] $MSG_HELP_ogCreateImage : ogCreateImage $1 $2 $REPO $4 $IMGPROG $IMGCOMP"
149ogCreateImage "$1" "$2" "$REPO" "/$4" "$IMGPROG" "$IMGCOMP" &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_IMAGE "ogCreteImage"; echo $?)
[d2f28cf]150RESUMECREATEIMAGE=$(grep "Total Time:" $OGLOGCOMMAND)
[e272d9e]151TIMEAUX2=$[SECONDS-TIME2]
[e7e3140]152ogEcho log session "      $RESUMECREATEIMAGE "
153ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX2/60]m $[TIMEAUX2%60]s"
[e272d9e]154
[d2f28cf]155# Extender sistema de archivos
[e272d9e]156TIME3=$SECONDS
[e7e3140]157ogEcho log session "[90] Extender sistema de archivos."
[2d40ba26]158ogExtendFs $1 $2 || exit $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; echo $?)
[e272d9e]159SIZEFS2=$(ogGetFsSize  $1 $2)
160TIMEAUX3=$[SECONDS-TIME3]
[e7e3140]161ogEcho log session "      $MSG_HELP_ogExtendFs  $NEWSIZEFS ->  $SIZEFS = $SIZEFS2: $[TIMEAUX3/60]m $[TIMEAUX3%60]s"
[e272d9e]162
163#TODO que hacer si error al extender sistemade archivos
[eb9424f]164
[e272d9e]165#resumen de la operacion
[4ceafc1]166IMGSIZE=$(ls -s `ogGetPath $REPO /$4.$IMGEXT`| cut -f1 -d" ")
167IMGOS=$(ogGetImageInfo `ogGetPath $REPO /$4.$IMGEXT`)
[e272d9e]168
169TIME=$[SECONDS-TIME1]
[e7e3140]170ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s"
171ogEcho log session "      FileSystem $PART with $NEWSIZEFS KB data created onto file-image as $4 and used $IMGSIZE KB across DFS $ogprotocol"
172ogEcho log session "      Image-file $4 metada: $IMGOS"
[d2f28cf]173
Note: See TracBrowser for help on using the repository browser.