close Warning: Failed to sync with repository "ogBrowser-Git": (1366, "Incorrect string value: '\\xF0\\x9F\\x93\\xA6 I...' for column 'message' at row 1"); repository information may be out of date. Look in the Trac log for more information including mitigation strategies.

source: client/shared/scripts/createDiffImage @ 3ab9022

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 3ab9022 was e2a7442, checked in by irina <irinagomez@…>, 13 years ago

#565 Sincronizadas. Se bloquean igual que las monoliticas. Al crear diferenciales se detecta si la particion es igual que la basica

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

  • Property mode set to 100755
File size: 8.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.
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
[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
28#*/ ##
[30ad471]29trap "onexit $1 $2 $3 \"$4\" \"$5\"" 1 2 3 6 9 14 15 EXIT
[f456755]30
[e27c4f4]31function onexit() {
32    local exit_status=$?
[e24b042]33    ogUnmountImage $3 "$5" $DIFFTYPE &>/dev/null
[e27c4f4]34    ogUnmountImage $3 "$4" $IMGEXT &>/dev/null
[3a61f94]35    if [ $exit_status -ne 4 ]; then
[e2a7442]36        ogUnlockImage "$3" "/$4.$IMGEXT" &>/dev/null
37        ogUnlockImage "$3" "/$5.$DIFFEXT" &>/dev/null
[3a61f94]38        ogUnlock $1 $2 &>/dev/null
39    fi
[e27c4f4]40    exit $exit_status
41}
[cd1f048]42
[d2b8d24]43#Carga el configurador del engine desde el fichero engine.cfg
44[ -z $OGENGINECONFIGURATE ] &&  source /opt/opengnsys/etc/engine.cfg
[cd1f048]45
46# Factor de calculo de Time out al crear imagen: valor por defecto en engine.cfg
[d2b8d24]47CREATESPEED=${CREATESPEED:-"100000*4"}
[f456755]48# Sistema de fichero de la imagen según kernel, menor que 3.7 EXT4. comparamos revision
49[  $(uname -r|cut -d. -f2) -lt 7 ] &&  IMGFS="EXT4" || IMGFS="BTRFS"
[791d013]50# % de compresion para estimacion tamaño imagen IMGFS="EXT4"
51ZSYNC=${ZSYNC:-"120"}
52# Si IMGFS="BTRFS" la compresion es mayor.
53[ $IMGFS == "BTRFS" ] && let ZSYNC=$ZSYNC-30
54
[1a632ba]55TIME1=$SECONDS
56
57PROG="$(basename $0)"
[e27c4f4]58# Si se solicita, mostrar ayuda.
59if [ "$*" == "help" ]; then
60    ogHelp  "$PROG: $MSG_HELP_createDiffImage" \
61            "$PROG ndisco nparticion REPO|CACHE base_image diff_image" \
62            "$PROG 1 1 REPO Windows7 Win7aula23"
63   exit 0
[1a632ba]64fi
65
[251c9e4]66[ $# -lt 5 ] && exit $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE base_image diff_image"; echo $?)
[e27c4f4]67
[1a632ba]68# Valores por defecto en etc/engine.cfg
69IMGEXT="img"
[e24b042]70DIFFEXT="img.diff"
71DIFFTYPE="diff"
[251c9e4]72REPOIP=$(ogGetRepoIp)
[ef938d2]73
74# Limpiamos los archivo de log
[791d013]75echo -n "" >$OGLOGCOMMAND
76[ "$(ogGetCaller)" == "RestaurarSoftIncremental" ] ||  echo -n "" > $OGLOGSESSION
[ef938d2]77
[251c9e4]78ogEcho log session  "[1] $MSG_SCRIPTS_START $0 $*"
[1a632ba]79
[d2b8d24]80# Comprobamos si la imagen diferencial o la particion estan bloqueada:
[251c9e4]81ogIsImageLocked "$3" "$5.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $5.$DIFFEXT"; echo $?)
82ogIsLocked "$1" "$2" && exit $(ogRaiseError session $OG_ERR_LOCKED  "$1 $2"; echo $?)
[d2b8d24]83
84# Comprobar si la imagen completa existe.
[251c9e4]85IMGFILE="$(ogGetPath "$3" "$4.$IMGEXT")" || exit $(ogRaiseError session $OG_ERR_NOTFOUND "$3 $4.$IMGEXT"; echo $?)
[d2b8d24]86
[e27c4f4]87# Comprobar que la imagen completa es sincronizable
[251c9e4]88ogIsSyncImage "$3" "$4" "img" || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$3 $4"; echo $?)
[d2b8d24]89# Comprobar que no está bloqueada
[251c9e4]90ogIsImageLocked "$3" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $4.$IMGEXT"; echo $?)
[d2b8d24]91
92# Si el repositorio es CACHE comprobamos que exista
93if [ "$3" == "CACHE" -o "$3" == "cache" ]; then
[251c9e4]94        ! ogFindCache >/dev/null && exit $(ogRaiseError session $OG_ERR_NOTCACHE "CACHE "; echo $?)
[d2b8d24]95fi
[1a632ba]96
97echo " " > $OGLOGCOMMAND
98
99# Obtener información de los parámetros de entrada.
[251c9e4]100PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2"; echo $?)
[e27c4f4]101#Comprobamos que la partición se puede montar.
[251c9e4]102ORIG=$(ogMount $1 $2) ||   exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2"; echo $?)
[1a632ba]103
[d2b8d24]104DIFFDIR="$(ogGetParentPath "$3" "/$5")"
105DIFFFILE="$DIFFDIR/$5.$DIFFEXT"
[1a632ba]106
[e2a7442]107ogLockImage "$3"  "/$4.$IMGEXT"
108ogLockImage "$3"  "/$5.$DIFFEXT"
[1a632ba]109
110# Comprobar consistencia del sistema de archivos.
111echo " " > $OGLOGCOMMAND
112SIZEFS=$(ogGetFsSize  $1 $2)
[251c9e4]113ogEcho log session "[20] $MSG_HELP_ogCheckFs  $1 $2 $SIZEFS (KB) "
[1a632ba]114ogUnmount $1 $2
[251c9e4]115ogCheckFs $1 $2 >$OGLOGCOMMAND || exit $(ogRaiseError session $OG_ERR_PARTITION "ogCheckFs $1 $2" ; echo $?)
[1a632ba]116
[cd1f048]117# Borramos ficheros de paginacion y configuracion
[791d013]118FSTYPE=$(ogGetFsType $1 $2)
119case "$FSTYPE" in
[cd1f048]120    EXT[234])
121        ogCleanLinuxDevices $1 $2
122        rm -rf $ORIG/tmp/*
123        ;;
124    NTFS)
[791d013]125        [ $(ogGetPath $1 $2 pagefile.sys) ] && ogDeleteFile $1 $2 pagefile.sys
126        [ $(ogGetPath $1 $2 hiberfil.sys) ] && ogDeleteFile $1 $2 hiberfil.sys
127        [ $(ogGetPath $1 $2 swapfile.sys) ] && ogDeleteFile $1 $2 swapfile.sys
[cd1f048]128        ;;
129esac
130
[1a632ba]131# Crear la imagen.
132echo " " > $OGLOGCOMMAND
133TIME2=$SECONDS
[251c9e4]134ogEcho log session "[40] $MSG_HELP_createDiffImage: $1 $2 $3 $4"
[1a632ba]135# Creamos la lista del contenido y lo situamos en la particion a copiar.
136
137# Montamos imagen completa (con la que vamos a comparar)
[1ee5d4d3]138ogMountImage $3 "$4" $IMGEXT >/dev/null
[d2b8d24]139
140# Comprobar que la imagen completa se ha montado
[251c9e4]141ogWaitMountImage $3 "$4" $IMGEXT || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?)
[1ee5d4d3]142
143# Creamos la informacion de la imagen.
[251c9e4]144ogEcho log session "[50] $MSG_HELP_ogCreateInfoImage "
[e24b042]145ogCreateInfoImage $1 $2 $3 "$4" "${DIFFTYPE}"
[e2a7442]146[ $? -eq $OG_ERR_NOTDIFFERENT ] &&  exit $(ogRaiseError session $OG_ERR_NOTDIFFERENT; echo $?)
[6c2dee2]147
[d2b8d24]148#Calculamos el tamaño de la imagen:
[1ee5d4d3]149ogMount $1 $2 >/dev/null
[1a632ba]150ogLock $1 $2
[ebc31ef5]151ogEcho log session  "     $MSG_SCRIPTS_CREATE_SIZE"
[1ee5d4d3]152cd $ORIG
[654d744]153SIZEDATA=$(grep -v "\/$" /tmp/ogimg.info | tr '\n' '\0'| du -x -c --files0-from=- 2>/dev/null|tail -n1 |cut -f1)
[791d013]154let SIZEREQUIRED=$SIZEDATA*$ZSYNC/100
[cd1f048]155# Tamaño minimo fichero imagen 300000
[d2b8d24]156[ $SIZEREQUIRED -lt 300000 ] && SIZEREQUIRED=300000
[1a632ba]157
[e27c4f4]158# Comprueba que quepa en el repositorio
[d2b8d24]159[ "$3" == "CACHE" -o "$3" == "cache" ] && SIZEFREE=$(ogGetFreeSize `ogFindCache`) && ogMountCache >/dev/null
160[ "$3" == "REPO"  -o "$3" == "repo"  ] && SIZEFREE=$(df -k | grep $OGIMG | awk '{print $4}')
[ebc31ef5]161ogEcho log session  "      $SIZEREQUIRED $SIZEFREE"
[251c9e4]162[ $SIZEREQUIRED -gt $SIZEFREE ] && exit $(ogRaiseError session $OG_ERR_CACHESIZE "$3"; echo $?)
[1ee5d4d3]163
[791d013]164TIMEAUX3=$[SECONDS-TIME2]
[251c9e4]165ogEcho log session "      $MSG_SCRIPTS_TASK_END $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX3/60]m $[TIMEAUX3%60]s"
[791d013]166
167# Del fichero de acl de la partición extraemos las acl de los ficheros de la diferencial
168if [ "$FSTYPE" == "NTFS" ]; then
[251c9e4]169        ogEcho log session "[55] $MSG_HELP_ogAclFilter "
[791d013]170        ogAclFilter
171        TIMEAUX4=$[SECONDS-TIMEAUX3]
[251c9e4]172        ogEcho log session "      $MSG_SCRIPTS_TASK_END $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX4/60]m $[TIMEAUX4%60]s"
[791d013]173fi
174TIMEAUX5=$[SECONDS-TIMEAUX3]
175
[1ee5d4d3]176# Configuro la informacion del tamaño de los datos en /tmp/ogimg.info
177sed -i s/SIZEDATA/"$SIZEDATA"/g /tmp/ogimg.info
[1a632ba]178
[d2b8d24]179# Creamos o redimensionamos la imagen
[251c9e4]180ogEcho log session "[60] $MSG_HELP_ogCreateFileImage."
[e24b042]181ogCreateFileImage $3 "$5" $DIFFTYPE $SIZEREQUIRED
[1a632ba]182
[d2b8d24]183# Esperamos que se monte la imagen despues de crarla en el servidor
[251c9e4]184ogWaitMountImage "$3" "$5" "$DIFFTYPE" $SIZEREQUIRED  || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $5 $DIFFTYPE: time_out."; echo $?)
[1a632ba]185
[251c9e4]186ogEcho log session  "[70] $MSG_HELP_ogSyncCreate"
[d2b8d24]187# Copio los datos a la imagen diferecial :
[e24b042]188ogSyncCreate $1 $2 $3 "$5" $DIFFTYPE
[c4db9c1]189RETVAL=$?
190[ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING"
[791d013]191TIMEAUX6=$[SECONDS-TIMEAUX5]
[ebc31ef5]192ogEcho log session   "      $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX6/60]m $[TIMEAUX6%60]s"
[d2b8d24]193
[6c2dee2]194# Reducimos la imagen diferencial -> solo para kernel <= 3.7, imagenes con FS ext4
[251c9e4]195ogEcho log session "[80] $MSG_HELP_ogReduceImage: $3 /$4.$IMGEXT"
[6c2dee2]196ogReduceImage  $3 "$5" $DIFFTYPE
[e2a7442]197# TODO: necesaria funcion que espere a que se reduzca la imagen para continuar el script
[1a632ba]198
[791d013]199echo " " > $OGLOGCOMMAND
[d2b8d24]200# Comprobamos que la imagen esta bien
[251c9e4]201ogEcho log session "[95] $MSG_HELP_ogCheckSyncImage"
[e2a7442]202sleep 10
[251c9e4]203ogCheckSyncImage $3 "$5" diff ||  exit $(ogRaiseError session $OG_ERR_IMAGE "$3 $5 diff"; echo $?)
[1a632ba]204
205#resumen de la operacion
[654d744]206IMGSIZE=$(ls -l --block-size=1024 "${DIFFFILE}"| cut -f5 -d" ")
[1a632ba]207TIME=$[SECONDS-TIME1]
[251c9e4]208ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s"
209ogEcho log session "      FileSystem $PART with $SIZEDATA KB data created onto file-image as $5 and used $IMGSIZE KB acros DFS rsync "
[c4db9c1]210
211# Si ha habido problema al sincronizar nos salimos con error
212[ $RETVAL == 0 ] || exit $OG_ERR_SYNCHRONIZING
Note: See TracBrowser for help on using the repository browser.