34 lines
849 B
Bash
34 lines
849 B
Bash
#!/bin/bash
|
|
echo Migrate PostgreSQL version
|
|
|
|
DB_PATH=/db
|
|
OLD_DB_PATH=/tmp/old_db
|
|
NEW_DB_PATH=/tmp/new_db
|
|
|
|
# Handle password
|
|
if [ -z "$POSTGRES_PASSWORD" ] || [ "$POSTGRES_PASSWORD" == " " ];
|
|
then
|
|
echo "Please specify database password in POSTGRES_PASSWORD env variable!"
|
|
exit 1;
|
|
fi
|
|
|
|
# Run database on a COPY of the database
|
|
cp -r "$DB_PATH" "$OLD_DB_PATH"
|
|
|
|
# Initialize NEW database
|
|
mkdir "$NEW_DB_PATH"
|
|
/postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile=<(printf "%s\n" "$POSTGRES_PASSWORD") || exit 1
|
|
|
|
|
|
# Perform migration
|
|
cd /tmp
|
|
/postgres/17/bin/pg_upgrade -b /postgres/16/bin/ -d "$OLD_DB_PATH" -D "$NEW_DB_PATH" -U "$POSTGRES_USER" || exit 2
|
|
|
|
|
|
# Replace database
|
|
echo "Replace database files..."
|
|
rm -rf "$DB_PATH"/*
|
|
cp -r "$NEW_DB_PATH"/* "$DB_PATH"
|
|
mv "$OLD_DB_PATH" "$DB_PATH"
|
|
|
|
echo "Done with migration." |