diff options
Diffstat (limited to 'client/engine/Rsync.lib')
-rwxr-xr-x | client/engine/Rsync.lib | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/client/engine/Rsync.lib b/client/engine/Rsync.lib index 0d750800..b45406b1 100755 --- a/client/engine/Rsync.lib +++ b/client/engine/Rsync.lib @@ -10,7 +10,7 @@ #*/ function ogCreateFileImage () { -local SIZEREQUIRED IMGDIR IMGFILE DIRMOUNT LOOPDEVICE IMGSIZE IMGEXT +local SIZEREQUIRED IMGDIR IMGFILE DIRMOUNT LOOPDEVICE IMGSIZE IMGEXT KERNELVERSION if [ "$*" == "help" ]; then ogHelp "$FUNCNAME" : "$MSG_HELP_ogCreateFileImage" \ @@ -28,6 +28,7 @@ fi SIZEREQUIRED=$4 [ $SIZEREQUIRED -lt 300000 ] && SIZEREQUIRED=300000 +KERNELVERSION=$(uname -r| awk '{printf("%d",$1);sub(/[0-9]*\./,"",$1);printf(".%02d",$1)}') if [ "$1" == "CACHE" -o "$1" == "cache" ]; then IMGDIR="$(ogGetParentPath "$1" "/$2")" @@ -64,8 +65,7 @@ if [ "$1" == "CACHE" -o "$1" == "cache" ]; then echo " truncate --size=>$SIZEREQUIRED k $IMGFILE" truncate --size=">$SIZEREQUIRED"k "$IMGFILE" &> $OGLOGCOMMAND # FS de la imagen segun la version del kernel: < 3.7 ext4, si >= btrfs - #if [[ "$(uname -r)" < "3.7" ]]; then - if [ $(uname -r|cut -d. -f2) -lt 7 ]; then + if [ $KERNELVERSION \< 3.7 ]; then losetup $LOOPDEVICE "$IMGFILE" echo " resize2fs -f $LOOPDEVICE" resize2fs -f $LOOPDEVICE &> $OGLOGCOMMAND @@ -83,8 +83,7 @@ if [ "$1" == "CACHE" -o "$1" == "cache" ]; then #Formateamos imagen losetup $LOOPDEVICE $IMGFILE # FS de la imagen segun la version del kernel: < 3.7 ext4, si >= btrfs - #if [[ "$(uname -r)" < "3.7" ]]; then - if [ $(uname -r|cut -d. -f2) -lt 7 ]; then + if [ $KERNELVERSION \< 3.7 ]; then echo " mkfs.ext4 -i 4096 -b 4096 -L "${2##*\/}" $LOOPDEVICE" mkfs.ext4 -i 4096 -b 4096 -L "${2##*\/}" $LOOPDEVICE 2>&1 |tee -a $OGLOGCOMMAND else @@ -119,8 +118,7 @@ function ogCreateInfoImage () { #@param 4 Nombre Imagen Basica (opcional en las completas) #@param 5 Tipo imagen [ img | diff ] #*/ -local IMGTYPE IMGDIRAUX DIRMOUNT DESTRSYNC PASSWORD OPTRSYNC USERRSYNC ORIG FSTYPE PART DIREMPTY IMGLIST IMGINFO IMGACL - +local IMGTYPE IMGDIRAUX DIRMOUNT DESTRSYNC PASSWORD OPTRSYNC USERRSYNC ORIG FSTYPE PART DIREMPTY IMGLIST IMGINFO IMGACL KERNELVERSION # Ayuda o menos de 5 parametros y la imagen no es basica if [ "$*" == "help" -o $# -lt 5 -a "$3" != "img" ]; then ogHelp "$FUNCNAME" : "$MSG_HELP_ogCreateInfoImage" \ @@ -178,8 +176,8 @@ rm -f $ORIG/ogimg.* 2>/dev/null SIZEDATA=${SIZEDATA:-"SIZEDATA"} # Incluimos información de la imagen. Segun el kernel sera ext4 o btrfs. -#if [[ "$(uname -r)" < "3.7" ]]; then -if [ $(uname -r|cut -d. -f2) -lt 7 ]; then +KERNELVERSION=$(uname -r| awk '{printf("%d",$1);sub(/[0-9]*\./,"",$1);printf(".%02d",$1)}') +if [ $KERNELVERSION \< 3.7 ]; then echo "#EXT4:NO:$FSTYPE:$SIZEDATA" > $IMGINFO else echo "#BTRFS:LZO:$FSTYPE:$SIZEDATA" > $IMGINFO @@ -498,7 +496,7 @@ function ogMountImage () { #@param 3 Tipo imagen [ img |diff ] #@return punto de montaje #*/ -local IMGEXT IMGFILE DIRMOUNT +local IMGEXT IMGFILE DIRMOUNT KERNELVERSION if [ "$*" == "help" ]; then ogHelp "$FUNCNAME": "$MSG_HELP_ogMountImage" \ @@ -531,7 +529,8 @@ else mkdir -p "/tmp/$DIRMOUNT" # FS de la imagen segun la version del kernel: < 3.7 ext4, si >= btrfs - if [ $(uname -r|cut -d. -f2) -lt 7 ]; then + KERNELVERSION=$(uname -r| awk '{printf("%d",$1);sub(/[0-9]*\./,"",$1);printf(".%02d",$1)}') + if [ $KERNELVERSION \< 3.7 ]; then mount -t ext4 -o loop "$IMGFILE" "/tmp/$DIRMOUNT" 1>/dev/null else mount -o compress=lzo "$IMGFILE" "/tmp/$DIRMOUNT" 1>/dev/null @@ -672,7 +671,7 @@ let TIMEOUT=$SIZE/$CREATESPEED until $(grep -i $STATE $LOCKFILE &>/dev/null) ; do [ $STATE = "mounted" -a -f "$DIRMOUNT/ogimg.info" ] && ogEcho session "" && return 0 TIMEAUX=$[SECONDS-TIME] - [ "$TIMEAUX" -lt "$TIMEOUT" ] || return $(ogRaiseError $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT"; echo $?) + [ "$TIMEAUX" -lt "$TIMEOUT" ] || return $(ogRaiseError $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?) echo -n "#" | tee -a $OGLOGSESSION $OGLOGFILE sleep 5 done @@ -812,7 +811,7 @@ file "$IMGFILE" | grep -i -e " BTRFS Filesystem " -e " ext4 filesystem " >/dev/n #@exception OG_ERR_NOTFOUND # 2 Fichero o dispositivo no encontrado. #*/ function ogCheckSyncImage () { -local IMGEXT IMGDIR IMGFILE DIRMOUNT RETVAL +local IMGEXT IMGDIR IMGFILE DIRMOUNT ISMOUNT RETVAL KERNELVERSION if [ "$*" == "help" ]; then ogHelp "$FUNCNAME": "$MSG_HELP_ogCheckSyncImage" \ @@ -833,10 +832,19 @@ IMGFILE="${IMGDIR}/$(basename "/$2").$IMGEXT" ogIsSyncImage $1 "$2" "${IMGEXT#*\.}" || return $(ogRaiseError $OG_ERR_DONTSYNC_IMAGE "$3 $4"; echo $?) +# Comprobamos que no esté montada (daria falso error) +if [ "$1" == "CACHE" -o "$1" == "cache" ]; then + $(df | grep "/tmp/mount/$2${IMGEXT#img}$" &>/dev/null) && ISMOUNT=TRUE +else + [ -f "$OGIMG/mount/$2${IMGEXT#img}/ogimg.info" ] && ISMOUNT=TRUE +fi +[ "$ISMOUNT" == TRUE ] && ogEcho session warning "$MSG_SYNC_NOCHECK" && return 0 + DIRMOUNT="/tmp/ogCheckImage$$" mkdir "$DIRMOUNT" # FS de la imagen segun la version del kernel: < 3.7 ext4, si >= btrfs -if [ $(uname -r|cut -d. -f2) -lt 7 ]; then +KERNELVERSION=$(uname -r| awk '{printf("%d",$1);sub(/[0-9]*\./,"",$1);printf(".%02d",$1)}') +if [ $KERNELVERSION \< 3.7 ]; then mount -t ext4 -o loop "$IMGFILE" "$DIRMOUNT" 2>&1 | tee -a $OGLOGCOMMAND RETVAL=${PIPESTATUS[0]} else |