1 | #!/bin/bash |
---|
2 | #___________________________________________________________________ |
---|
3 | # |
---|
4 | #@file ImagenesSincronizadas.lib |
---|
5 | #@brief Librería o clase ImagenesSincronizadas |
---|
6 | #@class ImagenesSincronizadas |
---|
7 | #@brief Funciones para la creación y restauración de imagenes por sincronización. |
---|
8 | #@version 1.0.4 |
---|
9 | #@warning License: GNU GPLv3+ |
---|
10 | #___________________________________________________________________ |
---|
11 | |
---|
12 | #Load engine configurator from engine.cfg file. |
---|
13 | #Carga el configurador del engine desde el fichero engine.cfg |
---|
14 | [ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg |
---|
15 | |
---|
16 | # Clear temporary file used as log track by httpdlog |
---|
17 | # Limpia los ficheros temporales usados como log de seguimieincludento para httpdlog |
---|
18 | echo " " > $OGLOGSESSION; echo " " > $OGLOGCOMMAND; echo " " > ${OGLOGCOMMAND}.tmp |
---|
19 | |
---|
20 | # Registro de inicio de ejecución |
---|
21 | #echo "[START Interface ] Run this command: $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
22 | echo "$MSG_INTERFACE_START $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
23 | |
---|
24 | # Solo ejecutable por OpenGnSys Client. |
---|
25 | PATH=$PATH:$(dirname $0) |
---|
26 | PROG=$(basename $0) |
---|
27 | CALLER=$(ogGetCaller) |
---|
28 | if [ "$CALLER" != "ogAdmClient" ]; then |
---|
29 | ogRaiseError $OG_ERR_NOTEXEC "$CALLER -> $PROG" |
---|
30 | exit $? |
---|
31 | fi |
---|
32 | |
---|
33 | #___________________________________________________________________ |
---|
34 | # |
---|
35 | # Variables globales |
---|
36 | #___________________________________________________________________ |
---|
37 | |
---|
38 | TIPOPARTICION="$(ogGetPartitionId $DISCO $PARTICION)"; # Tipo de particion |
---|
39 | SISTEMAFICHERO="$(ogGetOsType $DISCO $PARTICION)" # Sistema de ficheros |
---|
40 | PARTICION=$(ogMount $DISCO $PARTICION); # Monta partición |
---|
41 | REPOSITORIO="root@$IPREPOSITORIO::imagenes" # Ruta de las imagenes en el repositorio |
---|
42 | |
---|
43 | # Borrar archivos en destino |
---|
44 | OP_DELETE="--delete" |
---|
45 | if [ $NOBORRACHIVOS -eq 1 ]; then |
---|
46 | OP_DELETE="" |
---|
47 | fi |
---|
48 | |
---|
49 | #___________________________________________________________________ |
---|
50 | # |
---|
51 | # Crea un fichero con la clave remota del rsync y actualiza el |
---|
52 | # parámetro "--password-file" para que no se pida ésta en el proceso. |
---|
53 | #___________________________________________________________________ |
---|
54 | # |
---|
55 | f="/tmp/passrsync" # Creación del archivo de claves |
---|
56 | echo "passusuog">$f # Escribe dentro la clave remota |
---|
57 | chmod 400 $f # Es obligatorio que el archivo de claves tenga estos permisos |
---|
58 | FILE_PASSWD="--password-file=$f" |
---|
59 | |
---|
60 | |
---|
61 | #___________________________________________________________________ |
---|
62 | # |
---|
63 | # Función: montaCache |
---|
64 | # |
---|
65 | # Descripción: |
---|
66 | # |
---|
67 | # Monta la cache y devuelve la ruta hacía ella |
---|
68 | # |
---|
69 | # Parámetros: |
---|
70 | # |
---|
71 | # Ninguno |
---|
72 | #___________________________________________________________________ |
---|
73 | # |
---|
74 | function montaCache() |
---|
75 | { |
---|
76 | # Error si no existe caché |
---|
77 | if ! $(ogFindCache >/dev/null); then |
---|
78 | echo "" |
---|
79 | return |
---|
80 | fi |
---|
81 | cache=$(ogMountCache) |
---|
82 | echo $cache |
---|
83 | } |
---|
84 | #___________________________________________________________________ |
---|
85 | # |
---|
86 | # Función: editarLista |
---|
87 | # |
---|
88 | # Descripción: |
---|
89 | # |
---|
90 | # Edita lista de archivos a transferir para depurar lineas |
---|
91 | # |
---|
92 | # Parámetros: |
---|
93 | # |
---|
94 | # $1 Lista de entrada |
---|
95 | # $2 Lista de salida |
---|
96 | #___________________________________________________________________ |
---|
97 | # |
---|
98 | function editarLista() |
---|
99 | { |
---|
100 | # Edición: |
---|
101 | # a) Quitarle lineas que contengan './' |
---|
102 | # b) La primera linea (reporter del rsync) |
---|
103 | # c) Las dos últimas lineas del final (reporter del rsync) |
---|
104 | |
---|
105 | echo "Editando lista de archivos Entrada:$1 Salida:$2" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
106 | cat $1 | sed '/\.\//d' | sed '1d' | sed -n -e :a -e '1,2!{P;N;D;};N;ba'>$2 |
---|
107 | } |
---|
108 | |
---|
109 | #___________________________________________________________________ |
---|
110 | # |
---|
111 | # Función: crearImagen |
---|
112 | # |
---|
113 | # Descripción: |
---|
114 | # |
---|
115 | # Sincroniza archivos entre origen y destino. Al final del |
---|
116 | # proceso el contenido de destino será igual al de origen. |
---|
117 | # La creación de imagen siempre tiene lugar entre una partición |
---|
118 | # y un repositorio como origen y destino respectivamente. |
---|
119 | # |
---|
120 | # Parámetros: |
---|
121 | # |
---|
122 | # $1: Origen |
---|
123 | # $2: Destino |
---|
124 | # $3: Sistema de ficheros de la partición |
---|
125 | # $4: Vale 1=Para crear la lista de archivos a transferir |
---|
126 | # 2= Cuando se quiere sincronizar usando la lista |
---|
127 | # $5: Path a la lista de archivos |
---|
128 | #___________________________________________________________________ |
---|
129 | # |
---|
130 | function crearImagen() |
---|
131 | { |
---|
132 | case "$3" in |
---|
133 | Windows) |
---|
134 | OP_ARCHIVO="-aH" |
---|
135 | OP_EXCLUDE="--exclude '$PARTICION/pagefile.sys'" |
---|
136 | ;; |
---|
137 | Linux) |
---|
138 | OP_ARCHIVO="-alH" |
---|
139 | OP_EXCLUDE="--exclude '/tmp ..exclude '/proc' --exclude='/sys'" |
---|
140 | ;; |
---|
141 | esac |
---|
142 | |
---|
143 | FREG=$OGLOGCOMMAND # Por defecto se redirecciona al archivo de log de comandos |
---|
144 | |
---|
145 | case "$4" in |
---|
146 | 1) |
---|
147 | OP_ARCHIVO=$OP_ARCHIVO"nv" # Simulación para crear lista |
---|
148 | FREG=$5 |
---|
149 | ;; |
---|
150 | 2) |
---|
151 | OP_FILELIST="--files-from=$5" |
---|
152 | OP_ARCHIVO="$OP_ARCHIVO $OP_FILELIST" |
---|
153 | ;; |
---|
154 | esac |
---|
155 | |
---|
156 | OP_PASSWD=$FILE_PASSWD |
---|
157 | echo "rsync $OP_ARCHIVO $OP_DELETE $OP_EXCLUDE $OP_PASSWD $1 $2 " | tee -a $OGLOGSESSION $OGLOGFILE |
---|
158 | rsync $OP_ARCHIVO $OP_DELETE $OP_EXCLUDE $OP_PASSWD $1 $2>$FREG; |
---|
159 | } |
---|
160 | |
---|
161 | #___________________________________________________________________ |
---|
162 | # |
---|
163 | # Función: restaurarImagen |
---|
164 | # |
---|
165 | # Descripción: |
---|
166 | # |
---|
167 | # Sincroniza archivos entre origen y destino. Al final del |
---|
168 | # proceso el contenido de destino será igual al de origen. |
---|
169 | # La restauración de imagen siempre tiene lugar entre la caché |
---|
170 | # o un repositorio y una partición o carpeta como origen y destino |
---|
171 | # respectivamente. |
---|
172 | # |
---|
173 | # Parámetros: |
---|
174 | # |
---|
175 | # $1: Origen |
---|
176 | # $2: Destino |
---|
177 | # $3: Sistema de ficheros de la partición |
---|
178 | # $4: Indica si la sincronización es local o remota |
---|
179 | # 1: El origen o el destino es remoto |
---|
180 | # 2: Tanto el origen como el destino son locales |
---|
181 | #___________________________________________________________________ |
---|
182 | # |
---|
183 | function restaurarImagen() |
---|
184 | { |
---|
185 | case "$3" in |
---|
186 | Windows) |
---|
187 | OP_ARCHIVO="-aH" |
---|
188 | ;; |
---|
189 | Linux) |
---|
190 | OP_ARCHIVO="-alH" |
---|
191 | ;; |
---|
192 | esac |
---|
193 | |
---|
194 | case "$4" in |
---|
195 | 1) |
---|
196 | OP_PASSWD=$FILE_PASSWD |
---|
197 | ;; |
---|
198 | 2) |
---|
199 | OP_PASSWD="" |
---|
200 | ;; |
---|
201 | esac |
---|
202 | echo "rsync $OP_ARCHIVO $OP_DELETE $OP_PASSWD $1 $2" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
203 | rsync $OP_ARCHIVO $OP_DELETE $OP_PASSWD $1 $2>$OGLOGCOMMAND; |
---|
204 | } |
---|
205 | |
---|