Skip to content

Migrating data between instances

Matthew Hanlon edited this page Jul 13, 2016 · 4 revisions

The database used in local development is a SQLite database, whereas in production the database is MySQL. We cannot simply import a MySQL database dump into our SQLite database because of syntax differences between the two platforms. However, Django does provide a nice way to migrate data independent of the backing datastore.

To move data between instances use the Django dumpdata command.

Run an instance of the portal container with a production environment config. Map in a local volume to export data to:

user@localhost   $ docker run -it --rm -v /path/to/datadump:/datadump \
        --env-file /opt/chameleon/.chameleon.env chameleoncloud/portal:tag bash
root@<container> # ./manage.py dumpdata --natural -e contenttypes \
        -e admin -e auth.Permission -e reversion > /datadump/datadump.json
root@<container> # exit

Then we can use the loaddata command to load datadump.json into a secondary instance. We also need to flush the local database to empty all existing data. IMPORTANT: if you need to backup your local database do it now!

Download the datadump.json file and place it in the project directory so it will be available inside the local docker container.

user@localhost   $ docker-compose up -d
user@localhost   $ cp db.sqlite3 db.sqlite3.bak
user@localhost   $ cp /path/to/datadump/datadump.json .
user@localhost   $ docker exec -it portal_django_1 bash
root@<container> # ./manage.py flush --no-initial-data
root@<container> # ./manage.py migrate
root@<container> # ./manage.py loaddata datadump.json
Clone this wiki locally