One command to restore local PostgreSQL dump into kubectl pod?

3/23/2020

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.

-- eox.dev
kubernetes
postgresql

3 Answers

3/23/2020

If the file was in s3 or another location available to the pod, you could always have a script inside the container that can download the file and perform the restore, in a single bash file.
That should allow you to perform the restore in a single command.

-- Yaron Idan
Source: StackOverflow

3/23/2020

cat mybackup.dmp | kubectl exec -i ... -- pgrestore ...

Or something like that.

-- coderanger
Source: StackOverflow

3/23/2020

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
-- Anton Matsiuk
Source: StackOverflow