summaryrefslogtreecommitdiffstats
path: root/client/engine/Rsync.lib
diff options
context:
space:
mode:
authoririna <irinagomez@us.es>2013-10-11 12:40:20 +0000
committeririna <irinagomez@us.es>2013-10-11 12:40:20 +0000
commitf456755884247a72cf1af575a6e15c8c3fc92442 (patch)
tree0033af7e543e38c3022f704510858de03d086cab /client/engine/Rsync.lib
parentbe48687d995f88aeb4bb482e96e2c870bd82f568 (diff)
#565 adaptacion diferenciales al cliente 1.0.4., extension diferenciles img.diff
git-svn-id: https://opengnsys.es/svn/branches/version1.0@4059 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'client/engine/Rsync.lib')
-rwxr-xr-xclient/engine/Rsync.lib150
1 files changed, 118 insertions, 32 deletions
diff --git a/client/engine/Rsync.lib b/client/engine/Rsync.lib
index 8eb00fdb..25a96d36 100755
--- a/client/engine/Rsync.lib
+++ b/client/engine/Rsync.lib
@@ -45,7 +45,6 @@ if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
if [ -f "$IMGFILE" ]; then
# Si la imagen esta montada la desmonto
if [ -r "$DIRMOUNT/ogimg.info" ]; then
- echo "umount $DIRMOUNT" | tee -a $OGLOGSESSION $OGLOGFILE
umount "$DIRMOUNT"
[ $? -ne 0 ] && return $(ogRaiseError $OG_ERR_DONTUNMOUNT_IMAGE "$1 $2.$IMGEXT"; echo $?)
fi
@@ -62,27 +61,41 @@ if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
if [ $IMGSIZE -lt $SIZEREQUIRED ];then
echo " $MSG_SYNC_RESIZE" | tee -a $OGLOGSESSION $OGLOGFILE
echo " truncate --size=>$SIZEREQUIRED k $IMGFILE" | tee -a $OGLOGSESSION $OGLOGFILE
- truncate --size=">$SIZEREQUIRED"k $IMGFILE &> $OGLOGCOMMAND
- echo " mount -o compress=lzo $IMGFILE $DIRMOUNT"
- mount -o compress=lzo "$IMGFILE" "$DIRMOUNT" &> $OGLOGCOMMAND
- echo " btrfs filesystem resize max $DIRMOUNT"
- btrfs filesystem resize max "$DIRMOUNT" &> $OGLOGCOMMAND
+ 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
+ losetup $LOOPDEVICE "$IMGFILE"
+ echo " resize2fs -f $LOOPDEVICE"
+ resize2fs -f $LOOPDEVICE &> $OGLOGCOMMAND
+
+ else
+ echo " ogMountImage $1 "$2" $3"
+ ogMountImage $1 "$2" $3
+ echo " btrfs filesystem resize max $DIRMOUNT"
+ btrfs filesystem resize max "$DIRMOUNT" &> $OGLOGCOMMAND
+ fi
fi
else
echo " dd if=/dev/zero of=$IMGFILE bs=1024 count=$SIZEREQUIRED"
dd if=/dev/zero of="$IMGFILE" bs=1024 count=$SIZEREQUIRED &> $OGLOGCOMMAND
#Formateamos imagen
losetup $LOOPDEVICE $IMGFILE
- echo " mkfs.btrfs -L ${2##*\/} $LOOPDEVICE "
- mkfs.btrfs -L "${2##*\/}" $LOOPDEVICE &> $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
+ echo " mkfs.ext4 -i 4096 -b 4096 -L "${2##*\/}" $LOOPDEVICE"
+ mkfs.ext4 -i 4096 -b 4096 -L "${2##*\/}" $LOOPDEVICE &> $OGLOGCOMMAND
+ else
+ echo " mkfs.btrfs -L ${2##*\/} $LOOPDEVICE "
+ mkfs.btrfs -L "${2##*\/}" $LOOPDEVICE &> $OGLOGCOMMAND
+ fi
fi
- echo " mount -o compress=lzo $IMGFILE $DIRMOUNT"
- mount -o compress=lzo "$IMGFILE" "$DIRMOUNT" &> $OGLOGCOMMAND
- # si ya esta montado $? = 32
- [ $? -eq 0 -o $? -eq 32 ] || ogRaiseError $OG_ERR_IMAGE "$3 $4"
- touch "$DIRMOUNT/ogimg.info"
+ # Monto la imagen
+ ogMountImage $1 "$2" $3 &>/dev/null
+ [ $? -eq 0 ] || ogRaiseError $OG_ERR_IMAGE "$3 $4"
+ touch "$DIRMOUNT/ogimg.info"
- #fi
# Si existe dispositivo de loop lo borro.
[ $LOOPDEVICE ] && losetup -d $LOOPDEVICE 2>&1 &>/dev/null
@@ -159,7 +172,14 @@ rm $ORIG/ogimg.* 2>/dev/null
# En las diferenciales no sabemos el tamaño -> ponemos una constante.
SIZEDATA=${SIZEDATA:-"SIZEDATA"}
-echo "#BRTFS:LZO:$FSTYPE:$SIZEDATA" > $IMGINFO
+# 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
+ echo "#EXT4:LZO:$FSTYPE:$SIZEDATA" > $IMGINFO
+else
+ echo "#BTRFS:LZO:$FSTYPE:$SIZEDATA" > $IMGINFO
+fi
+
if [ "$IMGTYPE" == "img" ]; then
# Imagen Basica
echo " rsync -aHAXvn --delete $ORIG/ $DIREMPTY >> $IMGINFO" | tee -a $OGLOGSESSION $OGLOGFILE
@@ -169,7 +189,6 @@ if [ "$IMGTYPE" == "img" ]; then
else
# Imagen Diferencial
- # TODO en el echo quitar la $OPTRSYNC para que no se vea el fichero de claves
echo " rsync -aHAXvn$OPTRSYNC --delete $ORIG/ $DESTRSYNC a $IMGLIST" | tee -a $OGLOGSESSION $OGLOGFILE
rsync -aHAXvn$OPTRSYNC $PASSWORD --delete "$ORIG/" "$DESTRSYNC" >> $IMGLIST
sed -i -e s/"^sent.*.bytes\/sec"//g -e s/^total.*.speedup.*.$//g -e s/"sending.*.list"//g $IMGLIST
@@ -188,7 +207,7 @@ fi
# Guardamos el contenido de las acl (Solo win) Necesario particion desmontada (esta asi)
ogUnmount $1 $2
if [ $FSTYPE == "NTFS" ]; then
- echo " ntfs-3g.secaudit -b $PART /" |tee -a $OGLOGSESSION $OGLOGFILE
+ echo " ntfs-3g.secaudit -b $PART /" |tee -a $OGLOGSESSION $OGLOGFILE
ntfs-3g.secaudit -b $PART / > $IMGACL
fi
@@ -252,12 +271,14 @@ if [ $(wc -l $DEST/$IMGLN|cut -f1 -d" ") -ne 0 ]; then
fi
# Restauramos acl
-if [ "$(ogGetFsType $1 $2)" == "NTFS" ] ; then
+if [ "$(ogGetFsType $1 $2)" == "NTFS" -a -f $DEST/$IMGACL ] ; then
cd /
cp $DEST/$IMGACL /tmp
ogUnmount "$1" "$2"
echo " ntfs-3g.secaudit -se $PART" |tee -a $OGLOGSESSION $OGLOGFILE
ntfs-3g.secaudit -se $PART /tmp/$IMGACL
+ # Para evitar que de falso error
+ echo ""
fi
}
@@ -416,9 +437,22 @@ fi
DIRMOUNT=$(ogGetMountDir "$2" ${IMGEXT#*\.})
if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
+ # Si está montado nada que hacer.
+ df | grep "$DIRMOUNT$" 2>&1 >/dev/null && echo "/tmp/$DIRMOUNT" && return 0
+
IMGFILE=$(ogGetPath "$1" /"$2.$IMGEXT")
mkdir -p "/tmp/$DIRMOUNT"
- mount -o compress=lzo "$IMGFILE" "/tmp/$DIRMOUNT" 1>/dev/null
+
+ # 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
+ mount -t ext4 -o loop "$IMGFILE" "/tmp/$DIRMOUNT" 1>/dev/null
+ else
+ mount -o compress=lzo "$IMGFILE" "/tmp/$DIRMOUNT" 1>/dev/null
+ fi
+
+ # Comprobamos que se ha montado bien
+ [ $? -eq 0 ] || ogRaiseError $OG_ERR_DONTMOUNT_IMAGE "$1 $2 $3" || return $?
echo "/tmp/$DIRMOUNT"
else
@@ -554,8 +588,6 @@ echo ""
}
-# DA ERROR
-# ERROR: unable to resize 'imagen' - File too large
function ogReduceImage () {
#/**
# ogReduceImage
@@ -567,7 +599,7 @@ function ogReduceImage () {
#@exception OG_ERR_FORMAT # 1 formato incorrecto.
#@exception OG_ERR_NOTFOUND # 2 Fichero o dispositivo no encontrado.
#*/
-local IMGEXT DIRMOUNT AVAILABLE USED IMGDIR IMGFILE ENDSIZE
+local IMGEXT DIRMOUNT AVAILABLE USED IMGDIR IMGFILE ENDSIZE LOOPDEVICE
if [ "$*" == "help" ]; then
ogHelp "$FUNCNAME" "$FUNCNAME [ REPO|CACHE ] image_name [ extension ]" \
"$FUNCNAME REPO Ubuntu12" \
@@ -580,7 +612,13 @@ if [ $# -lt 2 ]; then
return $?
fi
+
[ "$3" == "" -o "$3" == "img" ] && IMGEXT="img" || IMGEXT="img.diff"
+IMGDIR=$(ogGetParentPath "$1" "/$2")
+IMGFILE="${IMGDIR}"/$(basename "/$2").$IMGEXT
+
+# Solo es posible para imagenes EXT4. Si no es EXT4 salimos sin error
+file $IMGFILE | grep -i " ext4 filesystem " 2>&1 > /dev/null || return 0
if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
# Al montar se comprueba la existencia de la imagen
@@ -588,21 +626,40 @@ if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
AVAILABLE=$(df -k|grep "$DIRMOUNT$"|awk '{print $4}')
# Si el espacio libre menor que 500Mb nos salimos
- if [ $AVAILABLE -lt 500000 ]; then
+ if [ $AVAILABLE -lt 200000 ]; then
ogUnmountImage $1 $2 ${IMGEXT#*\.}
return 0
fi
- # Reducimos el archivo de imagen:
- IMGDIR=$(ogGetParentPath "$1" "/$2")
- IMGFILE=${IMGDIR}/$(basename "/$2").$IMGEXT
- USED=$(df -k|grep "$DIRMOUNT$"|awk '{print $3}')
- let ENDSIZE=$USED+500000
- echo -e -n " btrfs filesystem resize "$ENDSIZE"k $DIRMOUNT \n "
- btrfs filesystem resize "$ENDSIZE"k $DIRMOUNT
+
+ # Calculamos la diferencia entre el tamaño interno y externo
+ EXTSIZE=$(ls -l --block-size=1024 $IMGFILE | cut -f5 -d" ")
+ INTSIZE=$(df -k|grep "$DIRMOUNT"|awk '{print $2}')
+ let EDGESIZE=$EXTSIZE-$INTSIZE
+
ogUnmountImage $1 $2 ${IMGEXT#*\.}
- echo " truncate --size=\"$ENDSIZE\"k $IMGFILE "
- truncate --size="$ENDSIZE"k $IMGFILE
+ LOOPDEVICE=$(losetup -f)
+ losetup $LOOPDEVICE "$IMGFILE"
+
+ # Redimensiono sistema de ficheros
+ echo resize2fs -fpM $LOOPDEVICE
+ resize2fs -fpM $LOOPDEVICE |tee -a $OGLOGCOMMAND
+ ogMountImage $1 $2 ${IMGEXT#*\.}
+
+ # Calculamos el tamaño final del archivo
+ INTSIZE=$(df -k|grep "$DIRMOUNT"|awk '{print $2}')
+ let EXTSIZE=$INTSIZE+$EDGESIZE
+ umount $DIRMOUNT
+
+ # Si existe dispositivo de loop lo borro.
+ [ $LOOPDEVICE ] && losetup -d $LOOPDEVICE
+
+ # Corto el archivo al tamaño del sistema de ficheros.
+ echo " truncate --size=\"$EXTSIZE\"k $IMGFILE "
+ truncate --size="$EXTSIZE"k $IMGFILE
+
+ rmdir $DIRMOUNT
+
else
[ -z $REPOIP ] && REPOIP=$(ogGetRepoIp)
echo " hose $REPOIP 2009 --out sh -c echo -ne REDUCE_IMAGE \"$2\" ${IMGEXT#*\.}"
@@ -614,8 +671,37 @@ fi
+function ogIsSyncImage () {
+#/**
+# ogIsSyncImage
+#@brief Comprueba si la imagen es sincronizable
+#@param 1 Repositorio [ REPO | CACHE ]
+#@param 2 Nombre Imagen
+#@param 3 Tipo Imagen [ img |diff ]
+#@return
+#@exception OG_ERR_FORMAT # 1 formato incorrecto.
+#@exception OG_ERR_NOTFOUND # 2 Fichero o dispositivo no encontrado.
+#*/
+local IMGEXT IMGDIR IMGFILE
+
+if [ "$*" == "help" ]; then
+ ogHelp "$FUNCNAME" "$FUNCNAME [ REPO|CACHE ] image_name [ extension ]" \
+ "$FUNCNAME REPO Ubuntu12" \
+ "$FUNCNAME CACHE Windows7 diff"
+ return
+fi
+if [ $# -lt 2 ]; then
+ ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME [ REPO|CACHE ] image_name [ extension ]"
+ return $?
+fi
+[ "$3" == "" -o "$3" == "img" ] && IMGEXT="img" || IMGEXT="img.diff"
+IMGDIR=$(ogGetParentPath "$1" "/$2")
+IMGFILE="${IMGDIR}"/$(basename "/$2").$IMGEXT
+file "$IMGFILE" | grep -i -e " BTRFS Filesystem " -e " ext4 filesystem " >/dev/null
+[ $? -eq 0 ] && return 0 || return $OG_ERR_DONTSYNC_IMAGE
+}