WIP: Prebuilt docker image #803
1 changed files with 11 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# USAGE:
|
||||
# migrate-postgresql-version.sh <data_directory> <old_version> <new_version>
|
||||
|
||||
|
@ -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"
|
Loading…
Reference in a new issue