Skip to content

Commit

Permalink
docs(dev): exporting pgdata
Browse files Browse the repository at this point in the history
  • Loading branch information
alanzhu0 committed Oct 2, 2022
1 parent 8af4555 commit 9df9523
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion SETUP.md
Expand Up @@ -2,7 +2,7 @@

You have two options when setting up a development environment for Ion: Docker or Vagrant. Docker is probably going to work better, so try it first.

**The Git repository on the host computer is synced with ``~/intranet`` on the virtual machine, so you can edit files within the repo on the host computer with a text editor of your choice and the changes will be immediately reflected on the virtual machine.**
The Git repository on the host computer is synced with ``~/intranet`` on the virtual machine, so you can edit files within the repo on the host computer with a text editor of your choice and the changes will be immediately reflected on the virtual machine.

# Docker

Expand All @@ -29,6 +29,10 @@ Navigate to http://localhost:8080 in the web browser of your choice. You might h

If you need to run a Django command like ``makemigrations``, ``collectstatic`` or ``shell_plus``, run ``docker exec -it application bash`` in your terminal. That wlll give you a shell into the application container. You can also use this to run scripts like ``build_sources.sh``. If you need to view the output from or restart ``runserver``, run ``docker attach application``.

### Attaching to logs

To view logs of a container, run `docker logs [CONTAINER NAME] -f`. For example, to view the logs of the web server, run `docker logs intranet -f`.

# Vagrant

## Prerequisites
Expand Down Expand Up @@ -138,3 +142,42 @@ You can find a list of file systems at ``intranet/apps/files/models.py``. To add
$ ./manage.py shell_plus
>>> Host.objects.create(name="Computer Systems Lab", code="csl", address="remote.tjhsst.edu", linux=True)

# Advanced

## Backup or export database from Docker

Use these instructions to create a backup of your development environment's postgres database and, if desired, import it into another container or Docker instance running on a different machine.

### Overview

For the Ion development environment, database information is stored in [Docker volumes](https://docs.docker.com/storage/volumes/), under the name `docker_pgdata`. On a linux environment, volumes are stored in `/var/lib/docker/volumes`.

### Creating a backup volume

To create a backup of your volume on your local device, make a copy of `/var/lib/docker/volumes/docker_pgdata` to a location you will remember.

### Mount to another container

To create another database container with the postgres data mounted, run:

``docker run -it -v docker_pgdata:/var/lib/postgresql/data postgres:latest /bin/bash``

### Export to another machine or Docker instance

Follow these steps to export your data if you are creating a new development environment on a different machine. These steps assume you already have a running dev environment on the target machine.

Warning: you are likely to see errors that you will have to Google and solve yourself. Only do this if you have a substantial amount of data you need for your new environment; otherwise, it's easier to simply create another environment and add the data manually.

1. Create a copy of your data in case something goes wrong (see creating a backup volume section).
2. On the new machine, copy the postgres volume to your volume directory. Do this either through an USB, other file transfer method, or SSH. If using `scp`, run:
``scp -r [USERNAME]@[HOST]:/var/lib/docker/volumes/docker_pgdata /var/lib/docker/volumes/``

Because you have copied over old configuration files to a new machine, the new postgres instance may think certain files are corrupted and not start. To correct this, do the following:

3. Create a container with the volume mounted:
``docker run -it -v /docker_pgdata:/var/lib/postgresql/data postgres:latest /bin/bash``
4. Run `apt update && apt install sudo`
5. Run `sudo -u postgres pg_resetwal /var/lib/postgresql/data`
6. Run `dd if=/dev/zero bs=1 count=8192 >> data/pg_xact/0000`
7. Exit the postgres container and restart your development environment. It should now contain all the data you had in your volume.
8. If something doesn't work, Google it...(and if you're feeling nice, add it here).

0 comments on commit 9df9523

Please sign in to comment.