From a0b37c3f34db45cc5a67c4866eef9a5d130929e1 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 17 Nov 2018 10:17:38 +0100 Subject: upgrade_pg.sh: Support major upgrades Signed-off-by: Florian Pritz --- upgrade_pg.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/upgrade_pg.sh b/upgrade_pg.sh index 21ee18a..2d95eb2 100755 --- a/upgrade_pg.sh +++ b/upgrade_pg.sh @@ -2,16 +2,14 @@ set -e ## Set the old version that we want to upgrade from. -TO_VERSION=$(pacman -Q postgresql | grep -Po '(?<=postgresql )[0-9]\.[0-9]') +TO_VERSION=$(pacman -Q postgresql | grep -Po '(?<=postgresql )[0-9]+\.[0-9]') to_major=$(echo "$TO_VERSION" | awk -F'.' '{print $1}') to_minor=$(echo "$TO_VERSION" | awk -F'.' '{print $2}') -if [[ ${to_major} -ne 9 ]]; then +if [[ ${to_major} -ne 11 ]]; then echo "WARNING: major upgrade detected, aborting..." exit 1 fi -from_major="${to_major}" -from_minor="$((to_minor - 1))" -export FROM_VERSION="${from_major}.${from_minor}" +export FROM_VERSION="$(cat /var/lib/postgres/data/PG_VERSION)" # free space check used_space=$(df --local --output=pcent /var/lib/postgres/ | grep -Po '[0-9]{1,3}(?=%)') @@ -31,8 +29,8 @@ su - postgres -c 'mkdir /var/lib/postgres/data' su - postgres -c "initdb --locale $LANG -E UTF8 -D /var/lib/postgres/data" vimdiff "/var/lib/postgres/data/pg_hba.conf" "/var/lib/postgres/data-${FROM_VERSION}/pg_hba.conf" vimdiff "/var/lib/postgres/data/postgresql.conf" "/var/lib/postgres/data-${FROM_VERSION}/postgresql.conf" -cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.crt" "/var/lib/postgres/data/server.crt" -cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.key" "/var/lib/postgres/data/server.key" +#cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.crt" "/var/lib/postgres/data/server.crt" +#cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.key" "/var/lib/postgres/data/server.key" systemctl stop postgresql.service su - postgres -c "pg_upgrade -b /opt/pgsql-${FROM_VERSION}/bin/ -B /usr/bin/ -d /var/lib/postgres/data-${FROM_VERSION} -D /var/lib/postgres/data" systemctl daemon-reload -- cgit v1.2.3-24-g4f1b