source: client/shared/scripts/createImage @ 6903f32

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 6903f32 was 946c54f, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.3, #499: Corregir errata al detectar tamaño del repositorio en script createImage.

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

  • Property mode set to 100755
File size: 6.3 KB
RevLine 
[f8f4dfa]1#!/bin/bash
[eb9424f]2
3#/**
4#         createImage
5#@brief   Scirpt de ejemplo para crear una imagen de un sistema de archivos.
6#@brief (puede usarse como base para el programa de creación de imágenes usado por OpenGnSys Admin).
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
[f311787]29 #@version 1.0.2 - Separacion de log
30#@author  Antonio J.Doblas Viso
31#@date   2011-08-4
[eb9424f]32#*/ ##
33
[2d40ba26]34# Test 1.  crear una imagen en un REPO sin espacio libre.
35# test 2.  crear una imagen en un REPO en modo solo lectura.
36# test 3.  intentar crear una imagen en la cache de un equipo que no la disponga.
37# test 4.  crear una imagen en la Cache sin espacio sufiente.
38# test 5.  intentar crear una imagen, en la que no se puede reducir el FS.
[f8f4dfa]39
[f5432db7]40TIME1=$SECONDS
[f311787]41
[e272d9e]42#Load engine configurator from engine.cfg file.
43#Carga el configurador del engine desde el fichero engine.cfg
[b92b4bb]44[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
45
[f311787]46
47
[f8f4dfa]48PROG="$(basename $0)"
49if [ $# -ne 4 ]; then
[be85bb2]50    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen"
[f8f4dfa]51    exit $?
52fi
53
[b92b4bb]54# Valores por defecto en etc/engine.cfg
55#IMGPROG="partclone"
56#IMGCOMP="lzop"
57#IMGEXT="img"
58#IMGREDUCE="TRUE"
[95b340a]59
[e272d9e]60echo "[1] $MSG_SCRIPTS_START $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE
[f311787]61
62
[defcdab]63# Si el repositorio es CACHE comprobamos que exista
[3aaf91d]64if [ "$3" == "CACHE" -o "$3" == "cache" ]; then
[2d40ba26]65    ! ogFindCache >/dev/null && exit $(ogRaiseError $OG_ERR_NOTCACHE "CACHE "; echo $?)
[3aaf91d]66fi
[defcdab]67
[f311787]68echo " " > $OGLOGCOMMAND
69
[c40a6b4]70# Obtener información de los parámetros de entrada.
[2d40ba26]71PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError $OG_ERR_PARTITION "$1 $2"; echo $?)
72
[f311787]73echo " " > $OGLOGCOMMAND
74
[2d40ba26]75#Comprobamos acceso de escritura.
76DIRTEMP=$(date +%Y%m%d-%H%M%S)
77ogMakeDir $3 /$4$DIRTEMP 2>/dev/null || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3"; echo $?) && ogDeleteTree $3 /$4$DIRTEMP
78
[f311787]79echo " " > $OGLOGCOMMAND
80
[a3fb8b2]81IMGDIR=$(ogGetParentPath "$3" "/$4")
[180a07dd]82# Si no existe, crear subdirectorio de la imagen.
83if [ $? != 0 ]; then
[e272d9e]84    echo "[5] $MSG_HELP_ogMakeDir \"$3 $(dirname "$4")." | tee -a $OGLOGSESSION $OGLOGFILE
[2d40ba26]85    ogMakeDir "$3" $(dirname "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
86    IMGDIR=$(ogGetParentPath "$3" "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
[180a07dd]87fi
[95b340a]88IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT
[f8f4dfa]89# Renombrar el fichero de imagen si ya existe.
90if [ -f "$IMGFILE" ]; then
[e272d9e]91        echo "[10] $MSG_SCRIPTS_FILE_RENAME \"$IMGFILE\" ->  \"$IMGFILE.ant\"." | tee -a $OGLOGSESSION $OGLOGFILE
92        mv "$IMGFILE" "$IMGFILE.ant"
[0fbc05e]93    mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null
[f8f4dfa]94fi
[2d40ba26]95
96#Comprobar espacio que requerira la imagen para ser almacenada
[e272d9e]97echo " " > $OGLOGCOMMAND
[2d40ba26]98if ogMount $1 $2 &>/dev/null
99then
100        SIZEDATA=$(df -k | grep $PART | awk '{print $3}')
101        #Aplicar factor de compresion
102        FACTORGZIP=55/100
103        FACTORLZOP=65/100
104        let SIZEREQUIRED=$SIZEDATA*$FACTORLZOP
105        #Comprobar espacio libre en el contenedor.
106        [ "$3" == "CACHE" ] && SIZEFREE=$(ogGetFreeSize `ogFindCache`)
[946c54f]107        [ "$3" == "REPO" ] && SIZEFREE=$(df -k | grep $OGIMG | awk '{print $4}')
[2d40ba26]108else
109        ogRaiseError $OG_ERR_PARTITION "$1 $2"
110    exit $?
111fi     
[e272d9e]112echo "[16] $PROG: $MSG_SCRIPTS_CREATE_SIZE  $SIZEREQUIRED $SIZEFREE" | tee -a $OGLOGSESSION $OGLOGFILE
[2d40ba26]113[ "$SIZEREQUIRED" -gt "$SIZEFREE" ] && exit $(ogRaiseError $OG_ERR_CACHESIZE "$3" || echo $?)
114
115
116# TODO: que hacer si la cache no tiene espacio libre.
[f8f4dfa]117
[e272d9e]118
[3aaf91d]119# Comprobar consistencia del sistema de archivos.
[e272d9e]120echo " " > $OGLOGCOMMAND
121SIZEFS=$(ogGetFsSize  $1 $2)
122echo "[20] $MSG_HELP_ogCheckFs  $PART $SIZEFS (KB) " | tee -a $OGLOGSESSION $OGLOGFILE
[914d834]123ogUnmount $1 $2
[2d40ba26]124ogCheckFs $1 $2 || exit $(ogRaiseError $OG_ERR_PARTITION "ogCheckFs $1 $2" && echo $?)
[914d834]125
[e272d9e]126
[f311787]127
[b92b4bb]128if [ "$IMGREDUCE" == "TRUE"   ]
129then
[e272d9e]130        echo "[30]: $MSG_HELP_ogReduceFs  "  | tee -a $OGLOGSESSION $OGLOGFILE
[b92b4bb]131        ogReduceFs $1 $2 || exit $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; echo $?)
[e272d9e]132        NEWSIZEFS=$(ogGetFsSize  $1 $2)
[b92b4bb]133        TIMEAUX=$[SECONDS-TIME1]
[e272d9e]134        echo "      $MSG_SCRIPTS_TIME_PARTIAL ( $NEWSIZEFS KB ) : $[TIMEAUX/60]m $[TIMEAUX%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
[b92b4bb]135fi
[914d834]136
[e272d9e]137
[f311787]138
[6d3f526]139# Crear la imagen.
[e272d9e]140echo " " > $OGLOGCOMMAND
141TIME2=$SECONDS
142echo "[40] $MSG_HELP_ogCreateImage : ogCreateImage $1 $2 $3 $4 $IMGPROG $IMGCOMP" | tee -a $OGLOGSESSION $OGLOGFILE
[2d40ba26]143ogCreateImage $1 "$2" $3 $4 "$IMGPROG" "$IMGCOMP" || exit $(ogRaiseError $OG_ERR_IMAGE "ogCreteImage"; echo $?)
[e272d9e]144RESUMECREATEIMAGE=$(cat $OGLOGCOMMAND | grep "Total Time:")
145TIMEAUX2=$[SECONDS-TIME2]
146echo "      $RESUMECREATEIMAGE " | tee -a $OGLOGSESSION $OGLOGFILE
147echo "      $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX2/60]m $[TIMEAUX2%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
148
149
[6d3f526]150
[e272d9e]151#Extender sistema de archivos
152TIME3=$SECONDS
[f311787]153echo "[90] Extender sistema de archivos." | tee -a $OGLOGSESSION $OGLOGFILE
[2d40ba26]154ogExtendFs $1 $2 || exit $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; echo $?)
[e272d9e]155SIZEFS2=$(ogGetFsSize  $1 $2)
156TIMEAUX3=$[SECONDS-TIME3]
157echo "      $MSG_HELP_ogExtendFs  $NEWSIZEFS ->  $SIZEFS = $SIZEFS2: $[TIMEAUX3/60]m $[TIMEAUX3%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
158
159
160#TODO que hacer si error al extender sistemade archivos
[eb9424f]161
[914d834]162
[f8f4dfa]163
[e272d9e]164#resumen de la operacion
165IMGSIZE=$(ls -s `ogGetPath $3 $4.img`| cut -f1 -d" ")
166IMGOS=$(ogGetImageInfo `ogGetPath $3 $4.img`)
167
168TIME=$[SECONDS-TIME1]
169echo "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s" | tee -a $OGLOGSESSION $OGLOGFILE
170echo "      FileSystem $PART with $NEWSIZEFS KB data created onto file-image as $4 and used $IMGSIZE KB acros DFS $ogprotocol " | tee -a $OGLOGSESSION $OGLOGFILE
171echo "      Image-file $4 metada: $IMGOS " | tee -a $OGLOGSESSION $OGLOGFILE
Note: See TracBrowser for help on using the repository browser.