WIP: Prebuilt docker image #803

Draft
floatingghost wants to merge 37 commits from customizable-docker-db into develop
Showing only changes of commit 8f8c7c76dc - Show all commits

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
set -euo pipefail
# USAGE: # USAGE:
# migrate-postgresql-version.sh <data_directory> <old_version> <new_version> # migrate-postgresql-version.sh <data_directory> <old_version> <new_version>
@ -14,7 +16,10 @@ old_version=$2
new_version=$3 new_version=$3
# Start a PostgreSQL 14 container # 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 # Dump the db from the old container
docker exec pg14 pg_dumpall -U postgres > dump.sql 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 # Stop the old container
docker stop pg14 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 # 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 # Load the db into the new container
docker exec -i pg16 psql -U postgres < dump.sql docker exec -i pg16 psql -U postgres < dump.sql
@ -37,4 +39,7 @@ docker stop pg16
# Remove the dump file # Remove the dump file
rm dump.sql 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"