Alle Projekte

Replicate PostgreSQL to Docker

PowerShell script that copies databases from a remote PostgreSQL server into a local Docker container in one go.

AI-generated
  • Tools

Why I built the script

When you work on an application, you often want to test with real data without touching the server it lives on. Getting there was the same every time: piece together pg_dump with the right parameters, start a Postgres container, create the databases, load the dumps. And all of that for each database separately. Not a hard process, but one where you have to look something up every single time.

So I put the steps into a script. It asks for what it needs and takes care of the rest.

Die vier Schritte des Skripts: Verbinden, Datenbanken auswählen, mit pg_dump sichern, in Docker oder einem anderen Host wiederherstellen

What it does

  • It connects to the source server and lists all databases. You pick some or take them all.
  • Each database is saved with pg_dump as an SQL file in a timestamped folder, so you get a backup along the way.
  • It starts a PostgreSQL container in Docker, optionally with a specific Postgres version and a local folder so the data survives a restart.
  • It loads the dumps there. Instead of Docker, the target can also be another PostgreSQL host.

Pitfalls it handles

  • No local client tools needed: If psql and pg_dump aren't installed, the script uses the ones from the Postgres image in Docker.
  • Umlauts: The export always runs in UTF-8, so characters like ä, ö and ü don't break along the way.
  • Reserved names: Databases like authorization are quoted correctly and can still be created.
  • Postgres 18 and newer: From version 18 on, the data directory in the official image is in a different place. The script detects this and mounts the right path; otherwise the data would silently not be saved.
  • Existing containers: If the container already exists, you can replace it or keep using it.

Try it

The script is open source (MIT) and runs on Windows with PowerShell and Docker Desktop. Start .\copy-psql-databases.ps1, answer the questions, done.

Go to the repository on GitHub

Alle Projekte
  • hello-eme-play

    Game engine that turns any website into a game, configured by a single JSON. With a plugin for Payload CMS.

    AI-generated
    • Tools
  • Moat

    A small PHP gate on the hosting you already have that keeps API keys out of the browser and forwards only approved requests. Still in development.

    AI-generated
    • Tools
  • bexio-dotnet

    .NET library for the bexio API (2.0 and 3.0): invoices, contacts, accounting and more, with personal access token or OAuth2 sign-in.

    AI-assisted
    • Tools

© 2026 Eme. See you space cowboy 2e78c88