source: client/shared/scripts/createDiffImage @ d2c8674

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 d2c8674 was 305c256, checked in by irina <irinagomez@…>, 7 years ago

Se corrigen erratas por usar el código de error de ogGetPath

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

  • Property mode set to 100755
File size: 7.7 KB
RevLine 
[1a632ba]1#!/bin/bash
2
3#/**
4#         createDiffImage
5#@brief   Script de ejemplo para crear una imagen diferencial de un sistema de archivos.
[5b825b50]6#@brief   Se usa como base para el programa de creación de imágenes de OpenGnsys Admin).
[1a632ba]7#@param 1 disco
8#@param 2 particion
9#@param 3 REPO|CACHE
[d2b8d24]10#@param 4 imagen_completa
11#@param 5 imagen_diferencial
[1a632ba]12#@return 
13#@exception OG_ERR_FORMAT     # 1 formato incorrecto.
14#@exception OG_ERR_PARTITION  # 3 Error en partición de disco o en su sistema de archivos
15#@exception OG_ERR_NOTFOUND   # Fichero de registro no encontrado.
16#@exception OG_ERR_IMAGE      # 5 Error en funcion ogCreateImage o ogRestoreImage.
17#@exception OG_ERR_NOTWRITE   # 14 error de escritura
18#@exception OG_ERR_NOTCACHE   # 15 si cache no existe 15
19#@exception OG_ERR_CACHESIZE  # 16 si espacio de la cache local o remota no tiene espacio 16
[e27c4f4]20#@exception OG_ERR_LOCKED          # 4 Partición o fichero bloqueado.
21#@exception OG_ERR_DONTMOUNT_IMAGE # 70 Error al montar una imagen sincronizada.
22#@exception OG_ERR_DONTSYNC_IMAGE  # 71 Imagen no sincronizable (es monolitica)
[1a632ba]23#@note  Se toma como punto de partida el script createImage.
24#@todo: que hacer, si el tamaño de la cache es sufciente, pero no tiene espacio libre
[e27c4f4]25#@version 1.0 - creacion de la diferencial con rsync y btrfs
[1a632ba]26#@author 
27#@date   2012-12-04
[e784187]28#@version 1.1.0 - Se muestra el espacio necesario para alojar la imagen y el disponible (ticket #771)
29#@author  Irina Gomez - ETSII Universidad de Sevilla
30#@date    2017-03-28
[1a632ba]31#*/ ##
[30ad471]32trap "onexit $1 $2 $3 \"$4\" \"$5\"" 1 2 3 6 9 14 15 EXIT
[f456755]33
[e27c4f4]34function onexit() {
35    local exit_status=$?
[e24b042]36    ogUnmountImage $3 "$5" $DIFFTYPE &>/dev/null
[e27c4f4]37    ogUnmountImage $3 "$4" $IMGEXT &>/dev/null
[3a61f94]38    if [ $exit_status -ne 4 ]; then
[e2a7442]39        ogUnlockImage "$3" "/$4.$IMGEXT" &>/dev/null
40        ogUnlockImage "$3" "/$5.$DIFFEXT" &>/dev/null
[3a61f94]41        ogUnlock $1 $2 &>/dev/null
42    fi
[e27c4f4]43    exit $exit_status
44}
[cd1f048]45
[d2b8d24]46#Carga el configurador del engine desde el fichero engine.cfg
47[ -z $OGENGINECONFIGURATE ] &&  source /opt/opengnsys/etc/engine.cfg
[cd1f048]48
[1a632ba]49TIME1=$SECONDS
50
51PROG="$(basename $0)"
[e27c4f4]52# Si se solicita, mostrar ayuda.
53if [ "$*" == "help" ]; then
54    ogHelp  "$PROG: $MSG_HELP_createDiffImage" \
55            "$PROG ndisco nparticion REPO|CACHE base_image diff_image" \
56            "$PROG 1 1 REPO Windows7 Win7aula23"
57   exit 0
[1a632ba]58fi
59
[251c9e4]60[ $# -lt 5 ] && exit $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE base_image diff_image"; echo $?)
[e27c4f4]61
[1a632ba]62# Valores por defecto en etc/engine.cfg
63IMGEXT="img"
[e24b042]64DIFFEXT="img.diff"
65DIFFTYPE="diff"
[251c9e4]66REPOIP=$(ogGetRepoIp)
[ef938d2]67
68# Limpiamos los archivo de log
[791d013]69echo -n "" >$OGLOGCOMMAND
70[ "$(ogGetCaller)" == "RestaurarSoftIncremental" ] ||  echo -n "" > $OGLOGSESSION
[ef938d2]71
[251c9e4]72ogEcho log session  "[1] $MSG_SCRIPTS_START $0 $*"
[1a632ba]73
[d2b8d24]74# Comprobamos si la imagen diferencial o la particion estan bloqueada:
[251c9e4]75ogIsImageLocked "$3" "$5.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $5.$DIFFEXT"; echo $?)
76ogIsLocked "$1" "$2" && exit $(ogRaiseError session $OG_ERR_LOCKED  "$1 $2"; echo $?)
[d2b8d24]77
78# Comprobar si la imagen completa existe.
[305c256]79IMGFILE="$(ogGetPath "$3" "$4.$IMGEXT")"
80[ -n "$IMGFILE" ] || exit $(ogRaiseError session $OG_ERR_NOTFOUND "$3 $4.$IMGEXT"; echo $?)
[d2b8d24]81
[e27c4f4]82# Comprobar que la imagen completa es sincronizable
[251c9e4]83ogIsSyncImage "$3" "$4" "img" || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$3 $4"; echo $?)
[d2b8d24]84# Comprobar que no está bloqueada
[251c9e4]85ogIsImageLocked "$3" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $4.$IMGEXT"; echo $?)
[d2b8d24]86
87# Si el repositorio es CACHE comprobamos que exista
88if [ "$3" == "CACHE" -o "$3" == "cache" ]; then
[251c9e4]89        ! ogFindCache >/dev/null && exit $(ogRaiseError session $OG_ERR_NOTCACHE "CACHE "; echo $?)
[d2b8d24]90fi
[1a632ba]91
92echo " " > $OGLOGCOMMAND
93
94# Obtener información de los parámetros de entrada.
[251c9e4]95PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2"; echo $?)
[e27c4f4]96#Comprobamos que la partición se puede montar.
[251c9e4]97ORIG=$(ogMount $1 $2) ||   exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2"; echo $?)
[1a632ba]98
[d2b8d24]99DIFFDIR="$(ogGetParentPath "$3" "/$5")"
100DIFFFILE="$DIFFDIR/$5.$DIFFEXT"
[1a632ba]101
[1a2fa9d8]102# Bloqueo las imagenes -> Si no hay acceso de escritura dara error y nos saldremos.
103ogLockImage "$3"  "/$4.$IMGEXT" || exit $?
104ogLockImage "$3"  "/$5.$DIFFEXT" || exit $?
[1a632ba]105
106# Comprobar consistencia del sistema de archivos.
107echo " " > $OGLOGCOMMAND
108SIZEFS=$(ogGetFsSize  $1 $2)
[251c9e4]109ogEcho log session "[20] $MSG_HELP_ogCheckFs  $1 $2 $SIZEFS (KB) "
[1a632ba]110ogUnmount $1 $2
[251c9e4]111ogCheckFs $1 $2 >$OGLOGCOMMAND || exit $(ogRaiseError session $OG_ERR_PARTITION "ogCheckFs $1 $2" ; echo $?)
[1a632ba]112
[cd1f048]113# Borramos ficheros de paginacion y configuracion
[d3dc88d]114ogCleanOs $1 $2
[cd1f048]115
[1a632ba]116# Crear la imagen.
117echo " " > $OGLOGCOMMAND
118TIME2=$SECONDS
[251c9e4]119ogEcho log session "[40] $MSG_HELP_createDiffImage: $1 $2 $3 $4"
[1a632ba]120# Creamos la lista del contenido y lo situamos en la particion a copiar.
121
122# Montamos imagen completa (con la que vamos a comparar)
[1ee5d4d3]123ogMountImage $3 "$4" $IMGEXT >/dev/null
[d2b8d24]124
125# Comprobar que la imagen completa se ha montado
[c8bbcdc]126ogWaitSyncImage $3 "$4" $IMGEXT "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?)
[1ee5d4d3]127
128# Creamos la informacion de la imagen.
[d3dc88d]129ogEcho log session "[45] $MSG_HELP_ogCreateInfoImage "
[e24b042]130ogCreateInfoImage $1 $2 $3 "$4" "${DIFFTYPE}"
[e2a7442]131[ $? -eq $OG_ERR_NOTDIFFERENT ] &&  exit $(ogRaiseError session $OG_ERR_NOTDIFFERENT; echo $?)
[6c2dee2]132
[d3dc88d]133#Comprobar espacio que requerira la imagen para ser almacenada
[31d4f1a5]134read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$3" "$5" DIFF)
[d3dc88d]135
[e784187]136ogEcho log session "[50] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED $SIZEFREE"
[d3dc88d]137[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$3"; echo $?)
138
[d2b8d24]139#Calculamos el tamaño de la imagen:
[1ee5d4d3]140ogMount $1 $2 >/dev/null
[1a632ba]141ogLock $1 $2
[1ee5d4d3]142
[791d013]143TIMEAUX3=$[SECONDS-TIME2]
[251c9e4]144ogEcho log session "      $MSG_SCRIPTS_TASK_END $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX3/60]m $[TIMEAUX3%60]s"
[791d013]145
146TIMEAUX5=$[SECONDS-TIMEAUX3]
147
[1ee5d4d3]148# Configuro la informacion del tamaño de los datos en /tmp/ogimg.info
149sed -i s/SIZEDATA/"$SIZEDATA"/g /tmp/ogimg.info
[1a632ba]150
[d2b8d24]151# Creamos o redimensionamos la imagen
[251c9e4]152ogEcho log session "[60] $MSG_HELP_ogCreateFileImage."
[e24b042]153ogCreateFileImage $3 "$5" $DIFFTYPE $SIZEREQUIRED
[1a632ba]154
[d2b8d24]155# Esperamos que se monte la imagen despues de crarla en el servidor
[c8bbcdc]156ogWaitSyncImage "$3" "$5" "$DIFFTYPE" "mounted" $SIZEREQUIRED  || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $5 $DIFFTYPE: time_out."; echo $?)
[1a632ba]157
[251c9e4]158ogEcho log session  "[70] $MSG_HELP_ogSyncCreate"
[d2b8d24]159# Copio los datos a la imagen diferecial :
[e24b042]160ogSyncCreate $1 $2 $3 "$5" $DIFFTYPE
[c4db9c1]161RETVAL=$?
162[ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING"
[791d013]163TIMEAUX6=$[SECONDS-TIMEAUX5]
[ebc31ef5]164ogEcho log session   "      $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX6/60]m $[TIMEAUX6%60]s"
[d2b8d24]165
[6c2dee2]166# Reducimos la imagen diferencial -> solo para kernel <= 3.7, imagenes con FS ext4
[251c9e4]167ogEcho log session "[80] $MSG_HELP_ogReduceImage: $3 /$4.$IMGEXT"
[6c2dee2]168ogReduceImage  $3 "$5" $DIFFTYPE
[c8bbcdc]169# Esperamos que el servidor termine de reducir la imagen
170ogWaitSyncImage "$3" "$5" $DIFFTYPE "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?)
[e2a7442]171# TODO: necesaria funcion que espere a que se reduzca la imagen para continuar el script
[1a632ba]172
[791d013]173echo " " > $OGLOGCOMMAND
[0d4cef22]174sleep 2
[d2b8d24]175# Comprobamos que la imagen esta bien
[251c9e4]176ogEcho log session "[95] $MSG_HELP_ogCheckSyncImage"
177ogCheckSyncImage $3 "$5" diff ||  exit $(ogRaiseError session $OG_ERR_IMAGE "$3 $5 diff"; echo $?)
[1a632ba]178
179#resumen de la operacion
[654d744]180IMGSIZE=$(ls -l --block-size=1024 "${DIFFFILE}"| cut -f5 -d" ")
[1a632ba]181TIME=$[SECONDS-TIME1]
[251c9e4]182ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s"
183ogEcho log session "      FileSystem $PART with $SIZEDATA KB data created onto file-image as $5 and used $IMGSIZE KB acros DFS rsync "
[c4db9c1]184
185# Si ha habido problema al sincronizar nos salimos con error
186[ $RETVAL == 0 ] || exit $OG_ERR_SYNCHRONIZING
Note: See TracBrowser for help on using the repository browser.