Database Backup - MUMT-IT/mis2018 GitHub Wiki

Backup data from pg container as plain text

Export data

Use pg_dump command to backup data and schema (backup data only fails to restore due to circular references). Flag --exclude-table-data to exclude alembic_version table.

$ docker exec -i mis2018_pg_1 pg_dump -U postgres -d mumtmis_dev | gzip -9 > mumtmis_dev20190703.pgsql.gz

Restore data using psql command.

Make sure the database is created. If not, run the following command in PostgreSQL.

$ createdb mumtmis_test;

Then run this command in Shell.

$ gunzip < mumtmis_dev20190703.pgsql.gz | psql -U postgres -p 5443 -h localhost -d mumtmis_test

Backup data from pg container as tar file.

Use pg_dump and pg_restore.

$ docker exec -i mis2018_pg_1 pg_dump -U postgres -F t -d mumtmis_dev > mumtmis_dev20190703.tar

Restoration:

$ pg_restore -U postgres -d mumtmis_test2 -h localhost -p 5443 mumtmis_dev20190703.tar