summaryrefslogtreecommitdiff
path: root/bin/sync/sync-wiki.sh
blob: 1be3cd68142ff7560fe0eb66a4827cece602b608 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# ----
# Copyright (C) 2013-2020 - Reevo Project (http://reevo.org)
# License: Affero GPL version 3 - http://www.gnu.org/licenses/agpl.html
# ES: Este archivos es parte de: reevo-web (http://git.reevo.org/reevo/reevo-web)
# EN: This file is part of: reevo-web (http://git.reevo.org/reevo/reevo-web)
# ----

cd /srv/reevotech

if [ -z $1 ];
then
    echo "You must specify the deployment codename"
    exit
fi

DEPLOY=$1
DEPLOYFILE=`ls ./etc | grep $DEPLOY`


echo $DEPLOY
cd /srv/reevotech/bin/sync/
REMOTO=`cat ../../etc/global_config-$DEPLOY.php | grep '^$REEVO_URL_PRODUCTION' | cut -d '"' -f 2`
RUTA=`cat ../../etc/global_config-$DEPLOY.php | grep '^$REEVO_PATH' | cut -d '"' -f 2`
DOMINIO=`cat $RUTA/etc/global_config-$DEPLOY.php | grep '^$REEVO_URL' | cut -d '"' -f 2`
USER=`cat $RUTA/etc/global_config-$DEPLOY.php | grep '^$REEVO_DB_USER' | cut -d '"' -f 2`
PASSWORD=`cat $RUTA/etc/global_config-$DEPLOY.php | grep '^$REEVO_DB_PASS' | cut -d '"' -f 2`

DB=`cat $RUTA/etc/global_config-$DEPLOY.php | grep '^$REEVO_DB_WIKI' | cut -d '"' -f 2`
TIMESTAMP=`date +%Y-%m-%d-%H:%M:%S`

# echo "REMOTO: $REMOTO"
# echo "RUTA: $RUTA"
# echo "DOMINIO: $DOMINIO"
# echo "USER: $USER"
# echo "PASSWORD: $PASSWORD"
# echo "DB: $DB"
# echo "TIMESTAMP: $TIMESTAMP"
#


echo "Vamos a sincronizar la BD y archivos desde $REMOTO hasta aqui $DOMINIO. Presione ENTER para continuar o cancele..."
read

echo ""
echo ""
echo "###################"
echo "Hacemos un backup de la base de datos que tenemos en este servidor"
../bkp/bkp_wiki.sh $DEPLOY


echo ""
echo ""
echo "###################"
echo "Generamos una copia de la BD en el servidor remoto"
ssh $REMOTO "$RUTA/bin/bkp/bkp_wiki.sh $DEPLOY"

echo ""
echo "Copiamos la BD desde el servidor hasta aqui"

scp "$REMOTO:$RUTA/bkp/wiki/ultimo" "/tmp/$REMOTO-$DB.sql.bz2"

echo ""
echo ""
echo "###################"
echo "Descomprimimos y reemplazamos la BD local por la remota"
rm "/tmp/*.sql"
bunzip2 "/tmp/$REMOTO-$DB.sql.bz2"
# mysql --user=$USER --password=$PASSWORD -e "CREATE database if not exists $BDIMPORT;"
mysql --user=$USER --password=$PASSWORD $DB <  "/tmp/$REMOTO-$DB.sql"

echo ""
echo ""
echo "###################"
echo "Vamos a sincronizar algunos directorios con archivos desde $REMOTO a este servidor"
sleep 2s

rsync -P -r -a -v -e "ssh -l reevo" --delete "$REMOTO:/srv/reevotech/files/wiki/$DEPLOY/" "/srv/reevotech/files/wiki/$DEPLOY/"
echo ""
echo "Borramos los temporales"
rm "/tmp/$REMOTO-$DB.sql"