source: client/shared/scripts/createImage @ d0c9a98

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 d0c9a98 was a6d6d6f, checked in by irina <irinagomez@…>, 9 years ago

#730 createImagen: La copia de seguridad de la imagen antigua se hace después de las comprobaciones.

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

  • Property mode set to 100755
File size: 6.8 KB
Line 
1#!/bin/bash
2
3#/**
4#@file    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 
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.
20#@note   
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
23#@version 1.0 - control de errores para el ogAdmServer
24#@author 
25#@date   2011-04-10
26#@version 1.0.1 - Control de espacio requerido
27#@author  Antonio J.Doblas Viso
28#@date   2011-05-10
29#@version 1.0.2 - Separacion de log
30#@author  Antonio J.Doblas Viso
31#@date   2011-08-4
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
35#*/ ##
36
37# Test 1.  crear una imagen en un REPO sin espacio libre.
38# test 2.  crear una imagen en un REPO en modo solo lectura.
39# test 3.  intentar crear una imagen en la cache de un equipo que no la disponga.
40# test 4.  crear una imagen en la Cache sin espacio sufiente.
41# test 5.  intentar crear una imagen, en la que no se puede reducir el FS.
42
43
44PROG="$(basename $0)"
45if [ $# -ne 4 ]; then
46    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen"
47    exit $?
48fi
49
50TIME1=$SECONDS
51
52#Load engine configurator from engine.cfg file.
53#Carga el configurador del engine desde el fichero engine.cfg
54[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
55
56# Valores por defecto en etc/engine.cfg
57#IMGPROG="partclone"
58#IMGCOMP="lzop"
59IMGEXT=${IMGEXT:-"img"}
60#IMGREDUCE="TRUE"
61REPO="${3^^}"
62
63# Unidad organizativa
64[ "$ogunit" != "" ] && OGUNIT="$ogunit"
65
66# Clear temporary file used as log track by httpdlog
67# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
68echo " " > $OGLOGSESSION; echo " " > $OGLOGCOMMAND; echo " " > ${OGLOGCOMMAND}.tmp
69
70ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*"
71
72# Si es una ip y es igual a la del equipo restaura desde cache
73[ "$REPO" == "$(ogGetIpAddress)" ] && REPO="CACHE"
74# Si es una ip y es distinta a la del recurso samba cambiamos de REPO.
75ogCheckIpAddress $REPO
76if [ $? == 0 -o $REPO == "REPO" ] ; then
77        # Si falla el cambio -> salimos con error repositorio no valido
78        ogChangeRepo $REPO $OGUNIT || exit $(ogRaiseError $OG_ERR_NOTFOUND '$REPO'; echo $?)
79        REPO="REPO"
80fi
81
82# Si el repositorio es CACHE comprobamos que exista
83if [ "$REPO" == "CACHE" ]; then
84    ! ogFindCache >/dev/null && exit $(ogRaiseError $OG_ERR_NOTCACHE "CACHE "; echo $?)
85fi
86
87# Obtener información de los parámetros de entrada.
88PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError $OG_ERR_PARTITION "$1 $2"; echo $?)
89
90#Comprobamos acceso de escritura.
91DIRTEMP=$(date +%Y%m%d-%H%M%S)
92ogMakeDir $REPO /$4$DIRTEMP 2>/dev/null || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO"; echo $?) && ogDeleteTree $REPO /$4$DIRTEMP
93
94IMGDIR=$(ogGetParentPath "$REPO" "/$4")
95# Si no existe, crear subdirectorio de la imagen.
96if [ $? != 0 ]; then
97    ogEcho log session "[5] $MSG_HELP_ogMakeDir \"$REPO $(dirname "$4")."
98    ogMakeDir "$REPO" $(dirname "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO /$4"; echo $?)
99    IMGDIR=$(ogGetParentPath "$REPO" "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO /$4"; echo $?)
100fi
101IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT
102
103echo " " > $OGLOGCOMMAND
104# Borramos ficheros de paginacion y configuracion
105ogCleanOs $1 $2
106
107#Comprobar espacio que requerira la imagen para ser almacenada
108read SIZEDATA SIZEREQUIRED ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$REPO")
109
110ogEcho log session "[16] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED"
111[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$REPO"; echo $?)
112
113# Comprobar consistencia del sistema de archivos.
114echo " " > $OGLOGCOMMAND
115SIZEFS=$(ogGetFsSize  $1 $2)
116ogEcho log session "[20] $MSG_HELP_ogCheckFs  $PART $SIZEFS (KB)"
117ogUnmount $1 $2 2>/dev/null
118ogCheckFs $1 $2 || exit $(ogRaiseError $OG_ERR_PARTITION "ogCheckFs $1 $2" && echo $?)
119
120# Evaluar variable de engine.cfg para reducir el sistema de archivos en la creacion
121if [ "$IMGREDUCE" == "TRUE" ]
122then
123    ogEcho log session "[30]: $MSG_HELP_ogReduceFs"
124    ogReduceFs $1 $2 &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; echo $?)
125    NEWSIZEFS=$(ogGetFsSize  $1 $2)
126    TIMEAUX=$[SECONDS-TIME1]
127    ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL ( $NEWSIZEFS KB ) : $[TIMEAUX/60]m $[TIMEAUX%60]s"
128fi
129
130# Renombrar el fichero de imagen si ya existe.
131if [ -f "$IMGFILE" ]; then
132    ogEcho log session "[10] $MSG_SCRIPTS_FILE_RENAME \"$IMGFILE\" ->  \"$IMGFILE.ant\"."
133    mv "$IMGFILE" "$IMGFILE.ant"
134    mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null
135    mv "$IMGFILE.sum" "$IMGFILE.sum.ant" 2>/dev/null
136    mv "$IMGFILE.full.sum" "$IMGFILE.full.sum.ant" 2>/dev/null
137fi
138
139# Crear la imagen.
140echo " " > $OGLOGCOMMAND
141TIME2=$SECONDS
142ogEcho log session "[40] $MSG_HELP_ogCreateImage : ogCreateImage $1 $2 $REPO $4 $IMGPROG $IMGCOMP"
143ogCreateImage "$1" "$2" "$REPO" "/$4" "$IMGPROG" "$IMGCOMP" &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_IMAGE "ogCreteImage"; echo $?)
144RESUMECREATEIMAGE=$(grep "Total Time:" $OGLOGCOMMAND)
145TIMEAUX2=$[SECONDS-TIME2]
146ogEcho log session "      $RESUMECREATEIMAGE "
147ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX2/60]m $[TIMEAUX2%60]s"
148
149# Extender sistema de archivos
150TIME3=$SECONDS
151ogEcho log session "[90] Extender sistema de archivos."
152ogExtendFs $1 $2 || exit $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; echo $?)
153SIZEFS2=$(ogGetFsSize  $1 $2)
154TIMEAUX3=$[SECONDS-TIME3]
155ogEcho log session "      $MSG_HELP_ogExtendFs  $NEWSIZEFS ->  $SIZEFS = $SIZEFS2: $[TIMEAUX3/60]m $[TIMEAUX3%60]s"
156
157#TODO que hacer si error al extender sistemade archivos
158
159#resumen de la operacion
160IMGSIZE=$(ls -s `ogGetPath $REPO /$4.$IMGEXT`| cut -f1 -d" ")
161IMGOS=$(ogGetImageInfo `ogGetPath $REPO /$4.$IMGEXT`)
162
163TIME=$[SECONDS-TIME1]
164ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s"
165ogEcho log session "      FileSystem $PART with $NEWSIZEFS KB data created onto file-image as $4 and used $IMGSIZE KB across DFS $ogprotocol"
166ogEcho log session "      Image-file $4 metada: $IMGOS"
167
Note: See TracBrowser for help on using the repository browser.