Cookiecutter Django project postgres migrating to new host

45 views Asked by At

I have a cookiecutter django template project working fine with a local postgres database.

(https://cookiecutter-django.readthedocs.io/en/latest/)

I've copied the git repository and recreated the docker images on a new host to run in production, but I would like to export/copy my data as well.

What's the recommended way to move the data over from the postgres docker instance ?

Thanks

2

There are 2 answers

2
Amir Mohseni On BEST ANSWER

You can generate a JSON output of all database data using the dumpdata command in Django. Transfer the JSON file to your host, and then reimport the data into the database. Refer to this article for a comprehensive guide on reading detailed instructions on the entire process.

https://cpske.github.io/ISP/django/data-import-export

0
Jordan On

Ok, figured it out.

I re-created the docker images (cookiecutter easily re-creates them with docker compose script after I copied the source over via git, but can also manually re-create or export) and then dump directly from postgres. In the case of cookiecutter in general, can just:

docker-compose -f local.yml exec postgres backup

and then copy over from the container to host:

docker cp <backup> <container_name> <path - usually /backup>

On the new host, copy the file back and:

docker compose -f local.yml exec postgres restore <filename>

For non-docker setups, you can just run "postgres backup" directly