From 8f8c7c76dcc542a6e75ad9736f5d94c7f87cac4b Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Wed, 29 May 2024 05:30:54 +0100 Subject: [PATCH] correct migration script --- docker-resources/migrate-postgresql-version.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docker-resources/migrate-postgresql-version.sh b/docker-resources/migrate-postgresql-version.sh index a22aa6a0f..6cfa3cbd4 100755 --- a/docker-resources/migrate-postgresql-version.sh +++ b/docker-resources/migrate-postgresql-version.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + # USAGE: # migrate-postgresql-version.sh @@ -14,7 +16,10 @@ old_version=$2 new_version=$3 # Start a PostgreSQL 14 container -docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$old_version-alpine +docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$old_version-alpine + +# wait a bit for the container to start +sleep 10 # Dump the db from the old container docker exec pg14 pg_dumpall -U postgres > dump.sql @@ -22,11 +27,8 @@ docker exec pg14 pg_dumpall -U postgres > dump.sql # Stop the old container docker stop pg14 -# move the data directory to a new location so we can overwrite it -mv $data_directory $data_directory.bak - # Start a PostgreSQL 16 container -docker run --rm -d --name pg16 -v $(pwd)/$data_directory:/var/lib/postgresql/data postgres:$new_version-alpine +docker run --rm -d --name pg16 -v $(pwd)/$data_directory.new:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$new_version-alpine # Load the db into the new container docker exec -i pg16 psql -U postgres < dump.sql @@ -37,4 +39,7 @@ docker stop pg16 # Remove the dump file rm dump.sql -echo "Migration complete! You can delete your old data directory by running 'rm -rf $data_directory.bak'" +echo "Migration complete! Your new database folder is $data_directory.new - you can now move your old data and replace it" + +echo "mv $data_directory $data_directory.old" +echo "mv $data_directory.new $data_directory" \ No newline at end of file