DockerPostgresMigration/README.md

23 lines
1.1 KiB
Markdown
Raw Normal View History

2024-12-05 15:59:05 +00:00
# Docker migration helper
2024-12-07 22:09:31 +00:00
This repo contains a `Dockerfile` that can helps you in performing your Docker images migration.
2024-12-05 15:59:05 +00:00
2024-12-07 22:09:31 +00:00
This repository will:
* Perform a temporary copy the old database
* Initialize a new empty database with the default user / password couple provided as environment variables (`POSTGRES_USER` and `POSTGRES_PASSWORD`)
* Run `pg_upgrade` from the copy of the old database to the new database
* Replace the old database with the new one
* Move the copy of the old database as sub-directory of the new database (in `old_db` directory, to allow rollback in case of failure)
## Perform the migration
Create an outdated database:
2024-12-06 10:32:50 +00:00
```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
2024-12-05 15:59:05 +00:00
```
2024-12-06 10:32:50 +00:00
2024-12-07 22:09:31 +00:00
Perform the migration (you need to replace `POSTGRES_USER` and `POSTGRES_PASSWORD` with the credentials of the root user of the database):
2024-12-06 10:32:50 +00:00
```bash
2024-12-07 22:09:31 +00:00
docker run -u 1000 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17
```