diff --git a/Dockerfile b/Dockerfile index 79f8053..b7c74be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,23 @@ RUN tar -xf pg16.tar.gz RUN cd postgresql* && ./configure --prefix=/postgres/16 && make world-bin && make install FROM ubuntu:noble -RUN apt update && apt install -y libicu74 libreadline8t64 curl wget nano && rm -rf /var/lib/apt/lists/* +RUN apt update && apt install -y \ + libicu74 \ + libreadline8t64 \ + curl \ + wget \ + nano \ + locales \ + && rm -rf /var/lib/apt/lists/* +RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +ENV LANG=en_US.utf8 + +ENV POSTGRES_USER=postgres + COPY --from=build17 /postgres/17 /postgres/17 -COPY --from=build16 /postgres/16 /postgres/16 \ No newline at end of file +COPY --from=build16 /postgres/16 /postgres/16 + +COPY migrate.sh /migrate.sh +RUN chmod +x migrate.sh + +CMD ["/migrate.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 8f4e80b..de6da4e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # Docker migration helper ## Test +Create an outdated database +```bash +mkdir test-db +docker run --rm --name testdb -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/var/lib/postgresql/data -it postgres:16 ``` -docker run --rm --name testdb -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/var/lib/postgresql/data -it postgres:16 + +Perform the migration: +```bash +./build.sh && docker run -u 1000 -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17 ``` \ No newline at end of file diff --git a/migrate.sh b/migrate.sh new file mode 100644 index 0000000..ad8b846 --- /dev/null +++ b/migrate.sh @@ -0,0 +1,28 @@ +#!/bin/bash +echo Migrate PostgreSQL version + +DB_PATH=/db +OLD_DB_PATH=/tmp/old_db + +# Run database on a COPY of the database +cp -r "$DB_PATH" "$OLD_DB_PATH" + +# Start the database in the background +/postgres/16/bin/postgres -D /tmp/old_db/ & + +while true; +do + echo Waiting for database... + if echo "\q" | /postgres/16/bin/psql -U "$POSTGRES_USER"; + then + break + fi +done + +# Perform dump + + +# Stop database +#pkill postgres + +bash \ No newline at end of file