summaryrefslogtreecommitdiffstats
path: root/client/shared/scripts/restoreDiffImage
diff options
context:
space:
mode:
authoririna <irinagomez@us.es>2013-04-12 12:30:19 +0000
committeririna <irinagomez@us.es>2013-04-12 12:30:19 +0000
commite27c4f4131565bb26180fe29c4be4a92f1009bca (patch)
treef9685e00a586365df293378b6eaa845533d06c22 /client/shared/scripts/restoreDiffImage
parent4085f13666d670d1d9c7b1849cf23094a88c61c9 (diff)
#565 Imagenes sincronizadas: control de errores
git-svn-id: https://opengnsys.es/svn/branches/version1.0@3742 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'client/shared/scripts/restoreDiffImage')
-rwxr-xr-xclient/shared/scripts/restoreDiffImage59
1 files changed, 39 insertions, 20 deletions
diff --git a/client/shared/scripts/restoreDiffImage b/client/shared/scripts/restoreDiffImage
index a108f275..2f986bd7 100755
--- a/client/shared/scripts/restoreDiffImage
+++ b/client/shared/scripts/restoreDiffImage
@@ -10,45 +10,65 @@
#@param 5 protocolo
#@param 6 opciones protocolo
#@return
-#@exception OG_ERR_FORMAT # 1 formato incorrecto.
-#@exception updateCache # 15 No hay cache
-#@exception updateCache # 16 no hay espacio sufiente
-#@exception "Error al montar la imagen" INTERNACIONALIZAR
+#@exception OG_ERR_FORMAT # 1 formato incorrecto.
+#@exception OG_ERR_NOTFOUND # 2 Fichero o dispositivo no encontrado
+#@exception OG_ERR_PARTITION# 3 Error en partición de disco.
+#@exception OG_ERR_LOCKED # 4 Partición o fichero bloqueado.
+#@exception updateCache # 15 No hay cache
+#@exception updateCache # 16 no hay espacio sufiente
+#@exception OG_ERR_DONTSYNC_IMAGE # 71 Imagen no sincronizable (es monolitica)
+#@exception OG_ERR_DONTMOUNT_IMAGE # 70 Error al montar una imagen sincronizada.
#@todo: Se puede dar la opcion de que mantenga los ficheros nuevos.
#@todo: Se puede dar la opcion que la trasferencia se manden los datos comprimidos.
#@version 1.0 - restauración de imagen con sincronizacion.
#@author
#@date 2012-12-04
#*/ ##
-trap "ogUnlockImage $1 /$2.$IMGEXT ; ogUnlock $3 $4; umount $DIRMOUNT; exit 1" 1 2 3 6 9 14 15
+trap "onexit $1 \"$2\" $3 $4" 1 2 3 6 9 14 15 ERR
+
+# Si salimos con error demontamos la imagen y desbloqueamos la imagen y la particion
+function onexit() {
+ local exit_status=$?
+ ogUnmountImage "$1" "$2" "$DIFFEXT" &>/dev/null
+ # Si la partición no estaba bloqueada -> la desbloqueo
+ [ $exit_status -eq 4 ] || ogUnlock $3 $4 &>/dev/null
+ exit $exit_status
+}
+
# Limpiamos los archivo de log
echo "" >$OGLOGCOMMAND
TIME1=$SECONDS
PROG="$(basename $0)"
-if [ $# -lt 4 ]; then
- ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE imagen[.sujijo] ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]"
- exit $?
+# Si se solicita, mostrar ayuda.
+if [ "$*" == "help" ]; then
+ ogHelp "$PROG: $MSG_HELP_restoreDiffImage" \
+ "$PROG REPO|CACHE diff_image ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]" \
+ "$PROG REPO Windows7_pc123 1 1 " \
+ "$PROG CACHE Ubuntu12_aula21 1 6 MULTICAST 9000:full-duplex:239.194.14.00:150M:50:60"
+ exit 0
fi
+[ $# -lt 4 ] && ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG REPO|CACHE diff_imagen ndisco nparticion [ UNICAST|MULTICAST|TORRENT ] [opciones protocolo]"
+
echo "[1] $MSG_SCRIPTS_START $0 $*" | tee -a $OGLOGFILE
# Procesar parámetros de entrada
DIFFEXT="diff"
-REPODIFFFILE=$(ogGetPath "REPO" "$2.$DIFFEXT") || exit $(ogRaiseError $OG_ERR_NOTFOUND "$2.$DIFFEXT"; echo $?)
+REPODIFFFILE=$(ogGetPath "REPO" "$2.$DIFFEXT") || ogRaiseError $OG_ERR_NOTFOUND "REPO $2.$DIFFEXT"
# Comprobamos si la imagen o la particion estan bloqueada:
-ogIsImageLocked "$1" "$2.$DIFFEXT" && exit $(ogRaiseError $OG_ERR_LOCKED "$1 $2.$DIFFEXT"; echo $?)
-ogIsLocked "$3" "$4" && exit $(ogRaiseError $OG_ERR_LOCKED "$3 $4"; echo $?)
+ogIsImageLocked "$1" "$2.$DIFFEXT" && ogRaiseError $OG_ERR_LOCKED "$1 $2.$DIFFEXT"
+ogIsLocked "$3" "$4" && ogRaiseError $OG_ERR_LOCKED "$3 $4"
+
+PART=$(ogDiskToDev "$3" "$4" 2>/dev/null ) || ogRaiseError $OG_ERR_PARTITION "$1 $2"
# Carga del configurador del engine
[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
# Comprobar que es sincronizable
-# TODO: crear mensaje de error.
-file $REPODIFFFILE | grep " BTRFS Filesystem" >/dev/null
-[ $? == 0 ] || exit $(ogRaiseError $OG_ERR_IMAGE "$3 $4"; echo $?)
+file $REPODIFFFILE | grep " BTRFS Filesystem" >/dev/null || ogRaiseError $OG_ERR_DONTSYNC_IMAGE "$3 $4"
PROTO=${5:-"UNICAST"}
@@ -71,24 +91,23 @@ if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
fi
TIME2=$SECONDS
-PART=$(ogDiskToDev "$3" "$4" 2>/dev/null ) || exit $(ogRaiseError $OG_ERR_PARTITION "$1 $2"; echo $?)
# Restaurar la imagen.
echo "[40] $MSG_RESTORE $PART"
# Montamos la diferencial
-ogMountImage "$1" "$2" "diff" &>/dev/null
+ogMountImage "$1" "$2" "$DIFFEXT" &>/dev/null
# Comprobar que la imagen diferencial se ha montado
-ogWaitMountImage "$1" "$2" "diff" || exit $(ogRaiseError $OG_ERR_DONTMOUNT_IMAGE "$3 $4 diff: time_out $TIMEAUX seg."; echo $?)
+ogWaitMountImage "$1" "$2" "$DIFFEXT" || ogRaiseError $OG_ERR_DONTMOUNT_IMAGE "$1 $2 $DIFFEXT: time_out $TIMEAUX seg."
ogMount $3 $4 >/dev/null
ogLock $3 $4
# Sincronizamos la partición con la imagen.
-echo "[60] $MSG_HELP_ogSyncRestore: $1 $2 diff $3 $4" |tee -a $OGLOGFILE
-ogSyncRestore "$1" "$2" "diff" $3 $4
+echo "[60] $MSG_HELP_ogSyncRestore: $1 $2 $DIFFEXT $3 $4" |tee -a $OGLOGFILE
+ogSyncRestore "$1" "$2" "$DIFFEXT" $3 $4
# Desmontamos la imagen
-ogUnmountImage "$1" "$2" "diff"
+ogUnmountImage "$1" "$2" "$DIFFEXT"
ogUnlock $3 $4
TIMEAUX2=$[SECONDS-TIME2]