Skip to content

Instantly share code, notes, and snippets.

@botkillern
Forked from ricjcosme/dump-restore
Created May 19, 2021 19:41
Show Gist options
  • Save botkillern/c24676a9d3e1bfbc517fefb1979c34f9 to your computer and use it in GitHub Desktop.
Save botkillern/c24676a9d3e1bfbc517fefb1979c34f9 to your computer and use it in GitHub Desktop.
DUMP / RESTORE PostgreSQL Kubernetes
DUMP
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
kubectl exec [pod-name] -- bash -c "pg_dump -U [postgres-user] [database-name]" > database.sql
RESTORE
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
cat database.sql | kubectl exec -i [pod-name] -- psql -U [postgres-user] -d [database-name]
@botkillern
Copy link
Author

Important!
If you got a error to found pod name. Specify the namespace

cat database.sql | kubectl exec --namespaces [namespace-name] -i [pod-name] -- psql -U [postgres-user] -d [database-name]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment