diff options
Diffstat (limited to 'client/shared/scripts/createDiffImage')
-rwxr-xr-x | client/shared/scripts/createDiffImage | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/client/shared/scripts/createDiffImage b/client/shared/scripts/createDiffImage index 79ee9726..ddee5c7b 100755 --- a/client/shared/scripts/createDiffImage +++ b/client/shared/scripts/createDiffImage @@ -28,16 +28,19 @@ #@version 1.1.0 - Se muestra el espacio necesario para alojar la imagen y el disponible (ticket #771) #@author Irina Gomez - ETSII Universidad de Sevilla #@date 2017-03-28 +#@version 1.1.1 - Varios repositorios para un mismo cliente (ticket #679). +#@author Irina Gomez - ETSII Universidad de Sevilla +#@date 2018/11/06 #*/ ## -trap "onexit $1 $2 $3 \"$4\" \"$5\"" 1 2 3 6 9 14 15 EXIT +trap "onexit $1 $2 \"$4\" \"$5\"" 1 2 3 6 9 14 15 EXIT function onexit() { local exit_status=$? - ogUnmountImage $3 "$5" $DIFFTYPE &>/dev/null - ogUnmountImage $3 "$4" $IMGEXT &>/dev/null + ogUnmountImage $REPO "$5" $DIFFTYPE &>/dev/null + ogUnmountImage $REPO "$3" $IMGEXT &>/dev/null if [ $exit_status -ne 4 ]; then - ogUnlockImage "$3" "/$4.$IMGEXT" &>/dev/null - ogUnlockImage "$3" "/$5.$DIFFEXT" &>/dev/null + ogUnlockImage "$IMGFILE" &>/dev/null + ogUnlockImage "$DIFFFILE" &>/dev/null ogUnlock $1 $2 &>/dev/null fi exit $exit_status @@ -59,33 +62,45 @@ fi [ $# -lt 5 ] && exit $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE base_image diff_image"; echo $?) -# Valores por defecto en etc/engine.cfg -IMGEXT="img" -DIFFEXT="img.diff" -DIFFTYPE="diff" -REPOIP=$(ogGetRepoIp) - # Limpiamos los archivo de log echo -n "" >$OGLOGCOMMAND [ "$(ogGetCaller)" == "RestaurarSoftIncremental" ] || echo -n "" > $OGLOGSESSION ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*" +# Valores por defecto en etc/engine.cfg +IMGEXT="img" +DIFFEXT="img.diff" +DIFFTYPE="diff" +REPO="${3^^}" +# No permite directorios diferentes para OU +OGUNIT="" + +# Si es una ip y es igual a la del equipo restaura desde cache +[ "$REPO" == "$(ogGetIpAddress)" ] && REPO="CACHE" +# Si es una ip y es distinta a la del recurso samba cambiamos de REPO. +ogCheckIpAddress $REPO +if [ $? == 0 -o $REPO == "REPO" ] ; then + # Si falla el cambio -> salimos con error repositorio no valido + ogChangeRepo $REPO $OGUNIT || exit $(ogRaiseError $OG_ERR_NOTFOUND '$REPO'; echo $?) + REPO="REPO" +fi + # Comprobamos si la imagen diferencial o la particion estan bloqueada: -ogIsImageLocked "$3" "$5.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $5.$DIFFEXT"; echo $?) +ogIsImageLocked "$REPO" "$5.$DIFFEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$REPO $5.$DIFFEXT"; echo $?) ogIsLocked "$1" "$2" && exit $(ogRaiseError session $OG_ERR_LOCKED "$1 $2"; echo $?) # Comprobar si la imagen completa existe. -IMGFILE="$(ogGetPath "$3" "$4.$IMGEXT")" -[ -n "$IMGFILE" ] || exit $(ogRaiseError session $OG_ERR_NOTFOUND "$3 $4.$IMGEXT"; echo $?) +IMGFILE="$(ogGetPath "$REPO" "$4.$IMGEXT")" +[ -n "$IMGFILE" ] || exit $(ogRaiseError session $OG_ERR_NOTFOUND "$REPO $4.$IMGEXT"; echo $?) # Comprobar que la imagen completa es sincronizable -ogIsSyncImage "$3" "$4" "img" || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$3 $4"; echo $?) +ogIsSyncImage "$REPO" "$4" "img" || exit $(ogRaiseError session $OG_ERR_DONTSYNC_IMAGE "$REPO $4"; echo $?) # Comprobar que no está bloqueada -ogIsImageLocked "$3" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $4.$IMGEXT"; echo $?) +ogIsImageLocked "$REPO" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$REPO $4.$IMGEXT"; echo $?) # Si el repositorio es CACHE comprobamos que exista -if [ "$3" == "CACHE" -o "$3" == "cache" ]; then +if [ "$REPO" == "CACHE" -o "$REPO" == "cache" ]; then ! ogFindCache >/dev/null && exit $(ogRaiseError session $OG_ERR_NOTCACHE "CACHE "; echo $?) fi @@ -96,12 +111,12 @@ PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError session $OG_ERR #Comprobamos que la partición se puede montar. ORIG=$(ogMount $1 $2) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2"; echo $?) -DIFFDIR="$(ogGetParentPath "$3" "/$5")" +DIFFDIR="$(ogGetParentPath "$REPO" "/$5")" DIFFFILE="$DIFFDIR/$5.$DIFFEXT" # Bloqueo las imagenes -> Si no hay acceso de escritura dara error y nos saldremos. -ogLockImage "$3" "/$4.$IMGEXT" || exit $? -ogLockImage "$3" "/$5.$DIFFEXT" || exit $? +ogLockImage "$REPO" "/$4.$IMGEXT" || exit $? +ogLockImage "$REPO" "/$5.$DIFFEXT" || exit $? # Comprobar consistencia del sistema de archivos. echo " " > $OGLOGCOMMAND @@ -116,25 +131,25 @@ ogCleanOs $1 $2 # Crear la imagen. echo " " > $OGLOGCOMMAND TIME2=$SECONDS -ogEcho log session "[40] $MSG_HELP_createDiffImage: $1 $2 $3 $4" +ogEcho log session "[40] $MSG_HELP_createDiffImage: $1 $2 $REPO $4" # Creamos la lista del contenido y lo situamos en la particion a copiar. # Montamos imagen completa (con la que vamos a comparar) -ogMountImage $3 "$4" $IMGEXT >/dev/null +ogMountImage $REPO "$4" $IMGEXT >/dev/null # Comprobar que la imagen completa se ha montado -ogWaitSyncImage $3 "$4" $IMGEXT "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?) +ogWaitSyncImage $REPO "$4" $IMGEXT "mounted" || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $4 $IMGEXT: time_out."; echo $?) # Creamos la informacion de la imagen. ogEcho log session "[45] $MSG_HELP_ogCreateInfoImage " -ogCreateInfoImage $1 $2 $3 "$4" "${DIFFTYPE}" +ogCreateInfoImage $1 $2 $REPO "$4" "${DIFFTYPE}" [ $? -eq $OG_ERR_NOTDIFFERENT ] && exit $(ogRaiseError session $OG_ERR_NOTDIFFERENT; echo $?) #Comprobar espacio que requerira la imagen para ser almacenada -read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$3" "$5" DIFF) +read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$REPO" "$5" DIFF) ogEcho log session "[50] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED $SIZEFREE" -[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$3"; echo $?) +[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$REPO"; echo $?) #Calculamos el tamaño de la imagen: ogMount $1 $2 >/dev/null @@ -150,31 +165,31 @@ sed -i s/SIZEDATA/"$SIZEDATA"/g /tmp/ogimg.info # Creamos o redimensionamos la imagen ogEcho log session "[60] $MSG_HELP_ogCreateFileImage." -ogCreateFileImage $3 "$5" $DIFFTYPE $SIZEREQUIRED +ogCreateFileImage $REPO "$5" $DIFFTYPE $SIZEREQUIRED # Esperamos que se monte la imagen despues de crarla en el servidor -ogWaitSyncImage "$3" "$5" "$DIFFTYPE" "mounted" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $5 $DIFFTYPE: time_out."; echo $?) +ogWaitSyncImage "$REPO" "$5" "$DIFFTYPE" "mounted" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $5 $DIFFTYPE: time_out."; echo $?) ogEcho log session "[70] $MSG_HELP_ogSyncCreate" # Copio los datos a la imagen diferecial : -ogSyncCreate $1 $2 $3 "$5" $DIFFTYPE +ogSyncCreate $1 $2 $REPO "$5" $DIFFTYPE RETVAL=$? [ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING" TIMEAUX6=$[SECONDS-TIMEAUX5] ogEcho log session " $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX6/60]m $[TIMEAUX6%60]s" # Reducimos la imagen diferencial -> solo para kernel <= 3.7, imagenes con FS ext4 -ogEcho log session "[80] $MSG_HELP_ogReduceImage: $3 /$4.$IMGEXT" -ogReduceImage $3 "$5" $DIFFTYPE +ogEcho log session "[80] $MSG_HELP_ogReduceImage: $REPO /$4.$IMGEXT" +ogReduceImage $REPO "$5" $DIFFTYPE # Esperamos que el servidor termine de reducir la imagen -ogWaitSyncImage "$3" "$5" $DIFFTYPE "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?) +ogWaitSyncImage "$REPO" "$5" $DIFFTYPE "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$REPO $4 $IMGEXT: time_out."; echo $?) # TODO: necesaria funcion que espere a que se reduzca la imagen para continuar el script echo " " > $OGLOGCOMMAND sleep 2 # Comprobamos que la imagen esta bien ogEcho log session "[95] $MSG_HELP_ogCheckSyncImage" -ogCheckSyncImage $3 "$5" diff || exit $(ogRaiseError session $OG_ERR_IMAGE "$3 $5 diff"; echo $?) +ogCheckSyncImage $REPO "$5" diff || exit $(ogRaiseError session $OG_ERR_IMAGE "$REPO $5 diff"; echo $?) #resumen de la operacion IMGSIZE=$(ls -l --block-size=1024 "${DIFFFILE}"| cut -f5 -d" ") |