210 lines
7.3 KiB
Bash
210 lines
7.3 KiB
Bash
#!/bin/bash
|
|
#___________________________________________________________________
|
|
#
|
|
# RESTAURAR IMAGEN INCREMENTAL
|
|
#___________________________________________________________________
|
|
#
|
|
# Parámetros recibidos desde el cliente:
|
|
#
|
|
# $1 Número de disco
|
|
# $2 Número de particion
|
|
# $3 Nombre canónico de la imagen básica (sin extensión)
|
|
# $4 Dirección del repositorio
|
|
# $5 Nombre canónico del software incremental (sin extensión)
|
|
# $6 Tipo de transmisión 0=Unicast 1=Multicast
|
|
# $7 Es una cadena "nnn" tipo flags que codifica varios parametros.
|
|
# Tiene el formato "nnn" donde "n" vale 0 ó 1.
|
|
# 1XX: Gestionar fichero completo en lugar de diferencas
|
|
# X1X: Eliminar archivos de la partición que no estén en la imagen
|
|
# XX1: Comprimir archivos para enviarlos por la red
|
|
# El valor X indica que no importa el valor que tenga el dato
|
|
# $8 Es una cadena "nnnn" tipo flags que codifica varios parametros.
|
|
# Tiene el formato "nnnn" donde "n" vale 0 ó 1.
|
|
# 1XXX: Borrar la particion de destino antes de restaurar la imagen basica
|
|
# X1XX: Copiar Imagen básica también a la cache
|
|
# XX1X: Borrar previamente la imagen basica de la cache antes de copiarla
|
|
# XXX1: No borrar archivos en destino
|
|
# El valor X indica que no importa el valor que tenga el dato
|
|
# $9 Método de clonación 0=Desde caché 1=Desde repositorio
|
|
# $10 Metodo de sincronizacion 1=Sincronización1 2=Sincronizacion2
|
|
# $11 Ruta de origen de la Imagen (Carpeta)
|
|
#___________________________________________________________________
|
|
#
|
|
# Control parámetros
|
|
#___________________________________________________________________
|
|
|
|
PROG="$(basename $0)"
|
|
if [ $# -lt 6 ]; then
|
|
usage=" ndisco nparticion nombre_imagen_basica ip_repositorio copiar_a_caché "
|
|
usage="$usage Borrar_cache_previamente metodo_clonación Ruta_origen"
|
|
ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG $usage"
|
|
exit $?
|
|
fi
|
|
|
|
DISCO=$1
|
|
NPART=$2
|
|
NOMBREIMG=$3
|
|
IPREPOSITORIO=$4
|
|
NOMBREIMGINC=$5
|
|
|
|
flag=$7
|
|
echo "flah:$flag">/tmp/log
|
|
WHLFILE=${flag:0:1}
|
|
RMVFILE=${flag:1:1}
|
|
CMPFILE=${flag:2:1}
|
|
|
|
flag=$8
|
|
echo "flah:$flag">/tmp/log
|
|
BORRARIMG=${flag:0:1}
|
|
COPIACACHE=${flag:1:1}
|
|
BORRACACHE=${flag:2:1}
|
|
NOBORRACHIVOS=${flag:3:1}
|
|
|
|
METCLONA=$9
|
|
RUTAORIGEN=${11}
|
|
#___________________________________________________________________
|
|
#
|
|
# Variables y configuración logs
|
|
#___________________________________________________________________
|
|
|
|
source /opt/opengnsys/scripts/ImagenesSincronizadas.lib
|
|
|
|
#___________________________________________________________________
|
|
#
|
|
# Activa navegador para ver progreso
|
|
#___________________________________________________________________
|
|
|
|
coproc /opt/opengnsys/bin/browser -qws http://localhost/cgi-bin/httpd-log.sh
|
|
#___________________________________________________________________
|
|
#
|
|
# Proceso
|
|
#___________________________________________________________________
|
|
|
|
echo "Restauracion de imagen incremental..." | tee -a $OGLOGSESSION $OGLOGFILE
|
|
|
|
# Borrado previo de la partición
|
|
if [ $BORRARIMG -eq 1 ]; then
|
|
if [ -n $RUTAORIGEN ]; then
|
|
echo "Borrando carpeta $PARTICION$RUTAORIGEN" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
rm -R $PARTICION$RUTAORIGEN
|
|
else
|
|
echo "Formateando la particion" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
ogFormat $DISCO $PARTICION $TIPOPARTICION
|
|
RETVAL=$?
|
|
if [ $RETVAL -ne 0 ]; then
|
|
kill $COPROC_PID
|
|
exit $OG_ERR_PARTITION
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Sincronización desde repositorio
|
|
if [ $METCLONA = 1 ]; then
|
|
if [ $COPIACACHE = 0 ]; then
|
|
echo "Restaurando imagen basica desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
ORIGEN="$REPOSITORIO/$NOMBREIMG/"
|
|
DESTINO=$PARTICION$RUTAORIGEN/
|
|
# Restauración de la imagen básica
|
|
echo "Sincronizando imagen basica entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1
|
|
RETVAL=$?
|
|
if [ $RETVAL -ne 0 ]; then
|
|
kill $COPROC_PID
|
|
exit $OG_ERR_IMAGE
|
|
fi
|
|
|
|
# Restauración de la imagen incremental
|
|
echo "Restaurando imagen incremental desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
ORIGEN="$REPOSITORIO/$NOMBREIMGINC/"
|
|
DESTINO=$PARTICION$RUTAORIGEN/
|
|
OP_DELETE=""
|
|
# Restauración de la imagen incremental
|
|
echo "Sincronizando imagen entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1
|
|
restauraListaAcl $ORIGEN $DESTINO $SISTEMAFICHERO $DISCO $NPART
|
|
RETVAL=$?
|
|
kill $COPROC_PID
|
|
echo "!!! Finaliza correctamente !!! la restauracion de imagen incremental $NOMBREIMGINC desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
exit $RETVAL
|
|
fi
|
|
fi
|
|
|
|
# Restauración desde la caché
|
|
echo "Restaurando desde la cache" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
|
|
# Comprobar si existe caché
|
|
CACHE=$(montaCache)
|
|
if [ -z $CACHE ]; then
|
|
echo "No se ha podido restaurar la imagen desde la cache" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
ogRaiseError $OG_ERR_NOTCACHE "CACHE"
|
|
kill $COPROC_PID
|
|
exit $?
|
|
fi
|
|
|
|
# Borrar imagen de la caché
|
|
if [ $BORRACACHE -eq 1 ]; then
|
|
echo "Borrando imagen basica $NOMBREIMG de la cache" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
rm -R $CACHE$OGIMG/$NOMBREIMG
|
|
echo "Borrando imagen incremental $NOMBREIMGINC de la cache" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
rm -R $CACHE$OGIMG/$NOMBREIMGINC
|
|
fi
|
|
|
|
# Actualización de la caché
|
|
echo "Actualizando cache local desde repositorio $IPREPOSITORIO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
|
|
ORIGEN="$REPOSITORIO/$NOMBREIMG/"
|
|
DESTINO="$CACHE$OGIMG/$NOMBREIMG/"
|
|
echo "Sincronizando imagen basica entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1
|
|
RETVAL=$?
|
|
if [ $RETVAL -ne 0 ]; then
|
|
kill $COPROC_PID
|
|
exit $OG_ERR_IMAGE
|
|
fi
|
|
ORIGEN="$REPOSITORIO/$NOMBREIMGINC/"
|
|
DESTINO="$CACHE$OGIMG/$NOMBREIMGINC/"
|
|
echo "Sincronizando imagen incremental entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 1
|
|
RETVAL=$?
|
|
if [ $RETVAL -ne 0 ]; then
|
|
kill $COPROC_PID
|
|
exit $OG_ERR_IMAGE
|
|
fi
|
|
|
|
echo "!!! Finaliza correctamente !!! copia de imagen basica e incremental a cache local" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
|
|
# Restauración desde caché a la partición
|
|
|
|
echo "Copiando imagen basica a la partición desde cache local" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
ORIGEN="$CACHE$OGIMG/$NOMBREIMG/"
|
|
DESTINO=$PARTICION$RUTAORIGEN/
|
|
echo "Sincronizando imagen entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 2
|
|
RETVAL=$?
|
|
if [ $RETVAL -ne 0 ]; then
|
|
kill $COPROC_PID
|
|
exit $OG_ERR_IMAGE
|
|
fi
|
|
|
|
echo "Copiando imagen incremental a la partición desde cache local" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
ORIGEN="$CACHE$OGIMG/$NOMBREIMGINC/"
|
|
DESTINO=$PARTICION$RUTAORIGEN/
|
|
OP_DELETE=""
|
|
echo "Sincronizando imagen entre $ORIGEN y $DESTINO" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
restaurarImagen $ORIGEN $DESTINO $SISTEMAFICHERO 2
|
|
restauraListaAcl $ORIGEN $DESTINO $SISTEMAFICHERO $DISCO $NPART
|
|
RETVAL=$?
|
|
if [ $RETVAL -ne 0 ]; then
|
|
kill $COPROC_PID
|
|
exit $OG_ERR_IMAGE
|
|
fi
|
|
echo "!!! Finaliza correctamente !!! restauracion imagen incremental $NOMBREIMGINC desde cache local" | tee -a $OGLOGSESSION $OGLOGFILE
|
|
#___________________________________________________________________
|
|
#
|
|
# Retorno
|
|
#___________________________________________________________________
|
|
|
|
kill $COPROC_PID
|
|
|
|
exit 0
|