upgrade: migrate postgres & greenlight data

This commit is contained in:
chandi 2025-03-12 00:21:55 +01:00
parent 2bee0acb10
commit da20874a6e
2 changed files with 75 additions and 6 deletions

57
scripts/postgres-migrate Executable file
View File

@ -0,0 +1,57 @@
#!/bin/bash -e
OLD_DATA_DIR=$(realpath "$1")
NEW_DATA_DIR=$(realpath "$2")
NEW_POSTGRES_VERSION=$3
if [ -d "$NEW_DATA_DIR" ]; then
echo "new postgres data directory $2 already exists. this is not expected"
exit 1
fi
OLD_PG_VERSION=$(cat "$OLD_DATA_DIR/PG_VERSION")
echo spin up a temporary postgres instance on $OLD_DATA_DIR
TEMP_CONTAINER_ID=$(docker run --detach --rm "-v=$OLD_DATA_DIR:/var/lib/postgresql/data" -e POSTGRES_HOST_AUTH_METHOD=trust postgres:$OLD_PG_VERSION-alpine)
until docker exec $TEMP_CONTAINER_ID psql -U postgres -c "select 1" > /dev/null 2>&1; do
echo "Waiting for postgres server..."
sleep 1
done
echo "find old greenlight database..."
if docker exec $TEMP_CONTAINER_ID psql -U postgres -lqt | cut -d \| -f 1 | grep greenlight-v3; then
OLD_DATABASE=greenlight-v3
elif docker exec $TEMP_CONTAINER_ID psql -U postgres -lqt | cut -d \| -f 1 | grep greenlight; then
OLD_DATABASE=greenlight
fi
echo "old database is called $OLD_DATABASE"
echo ""
echo "dumping data from old databse..."
GREENLIGHT_DUMP=$(mktemp)
docker exec $TEMP_CONTAINER_ID pg_dump -U postgres $OLD_DATABASE > $GREENLIGHT_DUMP
docker stop $TEMP_CONTAINER_ID
echo spin up a temporary postgres instance on $NEW_DATA_DIR
TEMP_CONTAINER_ID=$(docker run --detach --rm "-v=$NEW_DATA_DIR:/var/lib/postgresql/data" -e POSTGRES_HOST_AUTH_METHOD=trust postgres:$NEW_POSTGRES_VERSION-alpine)
until docker exec $TEMP_CONTAINER_ID psql -U postgres -c "select 1" > /dev/null 2>&1; do
echo "Waiting for postgres server..."
sleep 1
done
echo "create all databases..."
for database in "bbb_graphql" "hasura_app" "greenlight"; do
echo "creating $database"
docker exec $TEMP_CONTAINER_ID psql -U postgres -c "CREATE DATABASE $database;" -c "GRANT ALL PRIVILEGES ON DATABASE $database TO postgres;"
done
echo "restoring greenlight from dump..."
cat $GREENLIGHT_DUMP | docker exec -i $TEMP_CONTAINER_ID psql -U postgres greenlight
docker stop $TEMP_CONTAINER_ID

View File

@ -24,7 +24,7 @@ else
echo "# checking for old volumes & migrate them"
COMPOSE_PREFIX=$(docker compose config | grep '^name:' | awk '{print $2}')
function migrate {
function migrate_vol {
VOLUME=${COMPOSE_PREFIX}_${1}
EXISTING=$(docker volume ls | grep $VOLUME | tail -n1 | awk '{print $2}')
if [ -n "$EXISTING" ]; then
@ -36,12 +36,24 @@ else
docker volume rm $EXISTING
fi
}
migrate bigbluebutton ./data/bigbluebutton
migrate vol-freeswitch ./data/freeswitch-meetings
migrate vol-mediasoup ./data/mediasoup
migrate_vol bigbluebutton ./data/bigbluebutton
migrate_vol vol-freeswitch ./data/freeswitch-meetings
migrate_vol vol-mediasoup ./data/mediasoup
# TODO: migrate postgres database
# TODO: migrate greenlight-data
if [ -d "./postgres-data" ]; then
echo "folder ./postgres-data still exists and probably uses postgres 12. migrating to a fresh postgres 16 data directory..."
./scripts/postgres-migrate ./postgres-data ./data/postgres 16
mv postgres-data postgres-data.automigrate-bak
fi
if [ -d "./greenlight-data" ]; then
if [ -d "./data/greenlight" ]; then
mv ./data/greenlight ./data/greenlight.automigrate-bak
fi
mv ./greenlight-data ./data/greenlight
fi
# TODO: ask for LETSENCRYPT_EMAIL
echo ""
echo "# pull newest images"