Files
docker-postgis/upgrade-entrypoint.sh
Roman Vanicek 58c91a2567
All checks were successful
continuous-integration/drone/push Build is passing
Fix log path expansion
2026-03-29 20:26:49 +00:00

56 lines
1.7 KiB
Bash

#!/bin/bash
set -e
DATA_DIR="/var/lib/postgresql/data"
OLD_VERSION_FILE="$DATA_DIR/PG_VERSION"
NEW_VERSION="15"
OLD_BIN="/usr/lib/postgresql/14/bin"
NEW_BIN="/usr/lib/postgresql/15/bin"
if [ -f "$OLD_VERSION_FILE" ]; then
OLD_VERSION=$(cat "$OLD_VERSION_FILE")
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
echo "Data version ($OLD_VERSION) differs from engine ($NEW_VERSION). Starting upgrade..."
# Move old data to a temporary folder
mkdir -p $DATA_DIR/old_data
mv $DATA_DIR/* $DATA_DIR/old_data/ || true
# Initialize new data directory
mkdir $DATA_DIR/new_data
initdb -D $DATA_DIR/new_data
# Prevent error "You must have read and write access in the current directory."
cd $DATA_DIR
# Run pg_upgrade
# --link is used to avoid copying files (fast, but requires a backup!)
if ! pg_upgrade \
-d $DATA_DIR/old_data \
-D $DATA_DIR/new_data \
-b "$OLD_BIN" \
-B "$NEW_BIN" \
-s /tmp \
--link; then
echo "========================================"
echo "pg_upgrade FAILED! Here is the actual reason why the old server crashed:"
echo "========================================"
# Print the contents of the server log
cat "$DATA_DIR"/new_data/pg_upgrade_output.d/*/log/pg_upgrade_server.log
# Exit to prevent the script from continuing
exit 1
fi
# Clean-up
echo "Upgrade complete. Cleaning up..."
rm -rf $DATA_DIR/old_data
mv $DATA_DIR/new_data/* $DATA_DIR/
rmdir $DATA_DIR/new_data
fi
fi
exec $@