Skip to content

Importing the live SQL data

ashish-b10 edited this page Dec 2, 2018 · 4 revisions

This page will walk you through how to import the data from the server onto your machine.

Backing up the database on the server

If there is no up-to-date backup of the data on the server, first connect to it and run:

pg_dump --exclude-table=django_migrations \
  --exclude-table=django_content_type \
  --exclude-table=auth_permission \
  --username postgres \
  --data-only > ~/pg_dumps/$(date +%Y-%m-%d).sql

This will create a file in ~/pg_dumps/ with the date appended. Copy the file to your local machine using scp.

Importing the downloaded database

Assuming that the backup is safely copied over, it is now necessary to import the data.

If you are using PostgreSQL, first recreate the existing database - note that all existing saved data will be lost:

dropdb tmdb; createdb tmdb

Next, we must apply the appropriate database schema. First, we apply the full Django database schema. Then, we must revert the version of the tmdb project to the 0004_teammatch_competing schema as that is the one presently configured on the server:

python3 manage.py migrate
python3 manage.py migrate tmdb 0004_teammatch_competing

Finally, import the data from the server:

psql -d tmdb -f 2018-12-01.sql

At this point, the local database should be equivalent to the one running on the server. However, if you are interested in performing continued development, should apply recent migrations like so:

python3 manage.py migrate tmdb