Skip to content

Instantly share code, notes, and snippets.

@riprasad
Forked from ricjcosme/dump-restore
Last active September 1, 2023 09:05
Show Gist options
  • Save riprasad/f30db8fda8e33dd91c72a7aa084b8a60 to your computer and use it in GitHub Desktop.
Save riprasad/f30db8fda8e33dd91c72a7aa084b8a60 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]
===========
// DUMP
PGPASSWORD=<password> pg_dump -h [postgres-server-host] -U [user] [database_name] > backup.sql
//RESTORE
PGPASSWORD=<password> psql -h [ha-postgres-server-host] -U [user] [database_name] < backup.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment