Youtube GitHub LinkedIn Email
login
about use cases courses articles products events webinars services research websites Smart Aquaculture Developers AI Telemetry developers Computate Developers

How to backup and restore the Learn that computer database

by Christopher Tate

Connect to your OpenShift cluster running the database that needs to be backed up.

Make a directory on the pod for the backup

oc -n postgres exec $(oc -n postgres get pod -l postgres-operator.crunchydata.com/role=master -o name) -- \
  mkdir -p /pgdata/backup/

Back up the database

oc -n postgres exec $(oc -n postgres get pod -l postgres-operator.crunchydata.com/role=master -o name) -- \
  bash -c "pg_dump -U computateorg computateorglocal > /pgdata/backup/computateorglocal.sql"

Make a directory on your own computer for the database backup

mkdir -p ~/Downloads/backup/

Rsync the backup file to your computer

oc -n postgres rsync $(oc -n postgres get pod -l postgres-operator.crunchydata.com/role=master -o name):/pgdata/backup/ ~/Downloads/backup/

Connect to your OpenShift cluster running Postgres where you would like to restore the database.

Make a directory on the pod for the backup

oc -n postgres exec $(oc -n postgres get pod -l postgres-operator.crunchydata.com/role=master -o name) -- \
  mkdir -p /pgdata/restore/

Rsync the backup file to your Postgres pod

oc -n postgres rsync ~/Downloads/backup/ $(oc -n postgres get pod -l postgres-operator.crunchydata.com/role=master -o name):/pgdata/restore/

Drop the public schema and recreate a new public schema

oc -n postgres exec $(oc -n postgres get pod -l postgres-operator.crunchydata.com/role=master -o name) -- \
  bash -c "psql -U computateorg computateorglocal -c 'drop schema public cascade; create schema public; '"

Restore the database

oc -n postgres exec $(oc -n postgres get pod -l postgres-operator.crunchydata.com/role=master -o name) -- \
  bash -c "psql -U computateorg computateorglocal < /pgdata/restore/computateorglocal.sql"

Don't forget to share this page!

LinkedIn
Facebook
This site is open source
Generated with Computate
Powered by Google Kubernetes Engine