postgresqlkubernetes

One command to restore local PostgreSQL dump into kubectl pod?


I'm just seeing if there is one command to restore a local backup to a pod running postgres. I've been unable to get it working with:

kubectl exec -it <pod> -- <various commands>

So I've just resorted to:

kubectl cp <my-file> <my-pod>:<my-file>

Then restoring it.

Thinking there is likely a better way, so thought I'd ask.


Solution

  • You can call pg_restore command directly in the pod specifying path to your local file as a dump source (connection options may vary depending on image you're using), e.g:

    kubectl exec -i POD_NAME -- pg_restore -U USERNAME -C -d DATABASE < dump.sql