skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search