summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-12-07 10:42:26 +0100
committerFlorian Pritz <bluewind@xinu.at>2019-12-07 10:42:44 +0100
commit3e6596cd66f05eb45d9692621b3a8331606df92b (patch)
tree6b54acdfd242b2816b31c634aede446658172be1
parent6d97480ad014551f111e00777349ff7886114c70 (diff)
downloadbin-3e6596cd66f05eb45d9692621b3a8331606df92b.tar.gz
bin-3e6596cd66f05eb45d9692621b3a8331606df92b.tar.xz
upgrade_pg.sh: Merge Arch Linux changes; weaken disk free check
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xupgrade_pg.sh60
1 files changed, 39 insertions, 21 deletions
diff --git a/upgrade_pg.sh b/upgrade_pg.sh
index 2d95eb2..da07116 100755
--- a/upgrade_pg.sh
+++ b/upgrade_pg.sh
@@ -3,37 +3,55 @@ 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_major=$(echo "$TO_VERSION" | awk -F'.' '{print $1}')
-to_minor=$(echo "$TO_VERSION" | awk -F'.' '{print $2}')
-if [[ ${to_major} -ne 11 ]]; then
- echo "WARNING: major upgrade detected, aborting..."
+
+to_major=${TO_VERSION%%.*}
+if (( $to_major != 12 )); then
+ # NOTE: When this happens you should check the changelog and add any
+ # necessary changes here. Then bump the version check.
+ echo "ERROR: major upgrade detected, aborting..."
+ exit 1
+fi
+
+FROM_VERSION="$(cat /var/lib/postgres/data/PG_VERSION)"
+if [[ $FROM_VERSION == $TO_VERSION ]]; then
+ echo "ERROR: from and to versions are equal. Have you already updated?! Aborting..."
exit 1
fi
-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}(?=%)')
-if [[ ${used_space} -ge 50 ]]; then
- echo "ERROR: not enough free space for upgrade with backup, aborting..."
- exit 2
+if (( $used_space >= 50 )); then
+ echo "ERROR: not enough free space for upgrade with backup"
+ echo "hint enter to continue anyways"
+ read
+ #exit 2
fi
-pacman -S --needed postgresql-old-upgrade
-chown postgres:postgres /var/lib/postgres/
-if [[ -d "/var/lib/postgres/data-${FROM_VERSION}" ]]; then
- echo "ERROR: backup data-${FROM_VERSION} directory already exists, aborting..."
+if [[ -d /var/lib/postgres/data-$FROM_VERSION ]]; then
+ echo "ERROR: backup data-$FROM_VERSION directory already exists, aborting..."
exit 3
fi
-su - postgres -c "mv /var/lib/postgres/data /var/lib/postgres/data-${FROM_VERSION}"
+
+pacman -S --needed postgresql-old-upgrade
+chown postgres:postgres /var/lib/postgres/
+su - postgres -c "mv /var/lib/postgres/data /var/lib/postgres/data-$FROM_VERSION"
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"
+su - postgres -c 'chattr -f +C /var/lib/postgres/data' || :
+su - postgres -c 'initdb --locale en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data'
+vimdiff /var/lib/postgres/{data,data-$FROM_VERSION}/pg_hba.conf
+vimdiff /var/lib/postgres/{data,data-$FROM_VERSION}/postgresql.conf
+for f in {fullchain,chain,privkey}.pem; do
+ [[ -e $f ]] || continue
+ cp -avx /var/lib/postgres/data-$FROM_VERSION/$f /var/lib/postgres/data/$f
+done
+
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"
+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
systemctl start postgresql.service
-su - postgres -c '/var/lib/postgres/analyze_new_cluster.sh'
-su - postgres -c '/var/lib/postgres/delete_old_cluster.sh'
+
+su - postgres -c /var/lib/postgres/analyze_new_cluster.sh
+# We probably want to manually delete things for now in case this script misses
+# some stuff
+#su - postgres -c /var/lib/postgres/delete_old_cluster.sh