-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_postgres
More file actions
executable file
·62 lines (47 loc) · 2.72 KB
/
start_postgres
File metadata and controls
executable file
·62 lines (47 loc) · 2.72 KB
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
#!/bin/bash
source $HOME/.cache/envTiledViz
export PythonVENV=./TiledVizEnv_${DATE}
echo "===== 1 List and close active containers ====="
docker container ls -a --filter=name=$postgresNAME && docker container ls -a -q --filter=name=$postgresNAME |xargs docker rm -f -v
echo "===== 2 PostgreSQL container ====="
PostgresDock=postgres:13.21-alpine
if ( ! docker images --filter "reference=${PostgresDock}" >/dev/null ); then
docker pull ${PostgresDock}
sleep 2
fi
docker run -v $(pwd)/TVDatabase/postgresql/data:/var/lib/postgresql/data -p ${POSTGRES_PORT}:5432 -e PGPORT=${POSTGRES_PORT} -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_DB=$POSTGRES_DB -e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" --name=$postgresNAME ${PostgresDock} &
sleep 5
source $HOME/.cache/envTiledViz
# Update POSTGRES_HOST with the actual container IP
export POSTGRES_HOST=$(docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $postgresNAME)
source ${PythonVENV}/bin/activate
if ( $installX11 ); then
pathtodump=$(python3 -c "import zenipy; pathtodump=zenipy.zenipy.file_selection(title='Do you want to restore from a PostgreSQL dump file ? Please give the path to file or cancel if not : ', width=450, height=120, timeout=None); print(str(pathtodump))")
else
echo
echo
echo "Do you want to restore from a PostgreSQL dump file ? Please give the path to file or empty string if not"
read pathtodump;
fi
if [ X$pathtodump == X ]; then
echo "===== 3 Patch TiledViz DB definition ====="
replpass=$( echo $POSTGRES_PASSWORD | sed -e "s|\&|\\\&|g" )
sed -e "s| ENCRYPTED PASSWORD '\(.*\)';| ENCRYPTED PASSWORD '$replpass';|" TVDatabase/TiledViz.sql > $HOME/tmp/TiledViz.sql
export PGPASSWORD=$POSTGRES_PASSWORD
echo "===== 4 Apply TiledViz DB definition ====="
psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f $HOME/tmp/TiledViz.sql
rm $HOME/tmp/TiledViz.sql
sleep 2
echo "===== 5 Apply TiledViz management functions ====="
psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f TVDatabase/management.sql
else
echo "===== 3 Restore Old DB ====="
replpass=$( echo $POSTGRES_PASSWORD | sed -e "s|\&|\\\&|g" )
#sed -e "s| ENCRYPTED PASSWORD '\(.*\)';| ENCRYPTED PASSWORD '$replpass';|" TVDatabase/TiledViz_role.sql > $HOME/tmp/TiledViz_role.sql
#rm $HOME/tmp/TiledViz_role.sql
export PGPASSWORD=$POSTGRES_PASSWORD
psql -h ${POSTGRES_IP} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} -d ${POSTGRES_DB} < $pathtodump
#rm $pathtodump
fi
echo "===== 6 Build model ====="
sqlacodegen postgresql://${POSTGRES_USER}:"${POSTGRES_PASSWORD}"@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB} --outfile=TVDatabase/TVDb/models.py