Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto dev
  • Loading branch information
wlorenzetti committed Oct 11, 2024
2 parents 23f5206 + eba4849 commit b596842
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 17,881 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ WEBGIS_PUBLIC_HOSTNAME=dev.g3wsuite.it
# Persistent data folder (projects, database, uploads), mounted into "g3w-suite" container at: `/shared-volume`
WEBGIS_DOCKER_SHARED_VOLUME=./shared-volume

G3WSUITE_ADMIN_USERNAME=admin
G3WSUITE_ADMIN_PASS=admin

##
# 🚨 PostGIS DB
##
Expand Down
13 changes: 1 addition & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ projects
.idea
code

shared-volume/**

# DEMO DATA
!shared-volume/backup/
!shared-volume/backup/demo/
!shared-volume/backup/demo/**
!shared-volume/media/
!shared-volume/media/project_data/
!shared-volume/media/project_data/spatialite/
!shared-volume/media/project_data/spatialite/**
!shared-volume/media/projects/
!shared-volume/media/projects/3857_public-building-management-demo.qgs
shared-volume
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:
image: g3wsuite/g3w-suite:dev
environment:
- DISPLAY=:99
- G3WSUITE_ADMIN_USERNAME
- G3WSUITE_ADMIN_PASS
- G3WSUITE_TILECACHE_PATH
- G3WSUITE_POSTGRES_DBNAME
- G3WSUITE_POSTGRES_USER
Expand Down
45 changes: 33 additions & 12 deletions scripts/makefile/db-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,30 @@ DB_NAMES="${G3WSUITE_POSTGRES_DBNAME} data_production data_testing"
ID=${ID:-$PG_VERSION}

##
# Check ID
# Check ID:
#
# - /shared-volume/backup/${ID}
# - /tmp/g3w-suite-demo-projects/backup/${ID}
##
if [ -z `${DOCKER_COMPOSE} exec postgis bash -c "test -d /var/lib/postgresql/backup/${ID} && echo '1'"` ]; then
echo "invalid ID: $ID"
exit 1
if [ -z `${DOCKER_COMPOSE} exec g3w-suite bash -c "test -d /shared-volume/backup/${ID} && echo '1'"` ]; then

# Extract backup from remote repository
if [ ! -d "/tmp/g3w-suite-demo-projects" ]; then
bash -c "$DOCKER_COMPOSE exec g3w-suite git clone https://github.com/g3w-suite/g3w-suite-demo-projects.git --single-branch --depth 1 --branch master /tmp/g3w-suite-demo-projects"
else
bash -c "$DOCKER_COMPOSE exec g3w-suite git config --global --add safe.directory /tmp/g3w-suite-demo-projects"
bash -c "$DOCKER_COMPOSE exec g3w-suite git -C /tmp/g3w-suite-demo-projects pull https://github.com/g3w-suite/g3w-suite-demo-projects.git"
fi
if [ ! -z `${DOCKER_COMPOSE} exec g3w-suite bash -c "test -d /tmp/g3w-suite-demo-projects/backup/${ID} && echo '1'"` ]; then
bash -c "$DOCKER_COMPOSE exec g3w-suite cp -r /tmp/g3w-suite-demo-projects/backup/${ID} /shared-volume/backup"
fi

# check id (same as: /shared-volume/backup/${ID})
if [ -z `${DOCKER_COMPOSE} exec postgis bash -c "test -d /var/lib/postgresql/backup/${ID} && echo '1'"` ]; then
echo "invalid ID: $ID"
exit 1
fi

fi

##
Expand All @@ -47,21 +66,23 @@ rm .pgpass
##
echo "#!/bin/bash" > pg_restore.sh

# Waiting che creation of new cluster.

for DB in $DB_NAMES; do
cat >> pg_restore.sh << EOF
# Wait until database is ready
cat >> pg_restore.sh << EOF
until pg_isready; do
echo "wait 30s until is ready"
sleep 30;
done
EOF

for DB in $DB_NAMES; do
cat >> pg_restore.sh << EOF
psql ${DB_LOGIN} -d template1 -c "DROP DATABASE IF EXISTS ${DB}_1634;"
psql ${DB_LOGIN} -d template1 -c "create database ${DB}_1634;"
psql ${DB_LOGIN} -d template1 -c "CREATE DATABASE ${DB}_1634;"
pg_restore ${DB_LOGIN} -d ${DB}_1634 /var/lib/postgresql/backup/${ID}/${DB}.bck
psql ${DB_LOGIN} -d ${DB}_1634 -c "select postgis_extensions_upgrade();"
psql ${DB_LOGIN} -d ${DB}_1634 -c "SELECT postgis_extensions_upgrade();"
psql ${DB_LOGIN} -d template1 -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname='${DB}';"
psql ${DB_LOGIN} -d template1 -c "drop database ${DB};"
psql ${DB_LOGIN} -d template1 -c "alter database ${DB}_1634 rename to ${DB};"
psql ${DB_LOGIN} -d template1 -c "DROP DATABASE ${DB};"
psql ${DB_LOGIN} -d template1 -c "ALTER DATABASE ${DB}_1634 RENAME TO ${DB};"
EOF
done

Expand Down
Binary file removed shared-volume/backup/demo/data_production.bck
Binary file not shown.
Binary file removed shared-volume/backup/demo/data_testing.bck
Binary file not shown.
Binary file removed shared-volume/backup/demo/g3wsuite.bck
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b596842

Please sign in to comment.