login
articles map models fish populations fish farms fishing docks fish processing plants fishing trips events fishing boats

How to backup and restore the Smart Aquaculture 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 smartaquaculture smartaquaculturelocal > /pgdata/backup/smartaquaculturelocal.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 smartaquaculture smartaquaculturelocal -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 smartaquaculture smartaquaculturelocal < /pgdata/restore/smartaquaculturelocal.sql"

Don't forget to share this page!

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