Skip to content

Commit a6b7044

Browse files
authored
Merge pull request #994 from NASA-IMPACT/993-add-sqldumprestorationmd-file
Add SQLDumpRestoration.md file
2 parents 3bc4b74 + a7f823a commit a6b7044

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ $ docker cp /path/to/your/backup.json container_name:/path/inside/container/back
116116
$ docker-compose -f local.yml run --rm django python manage.py loaddata /path/inside/the/container/backup.json
117117
$ docker-compose -f local.yml run --rm django python manage.py migrate
118118
```
119+
### Restoring the Database from a SQL Dump
120+
If the JSON file is particularly large (>1.5GB), Docker might struggle with this method. In such cases, you can use SQL dump and restore commands as an alternative, as described [here](./SQLDumpRestoration.md).
121+
122+
119123

120124
## Additional Commands
121125

@@ -191,8 +195,7 @@ Documented [here](https://github.com/NASA-IMPACT/sde-indexing-helper/wiki/How-to
191195

192196
## Adding New Features/Fixes
193197

194-
1. Start with a [GitHub issue](https://github.com/NASA-IMPACT/sde-indexing-helper/issues).
195-
2. Use the GitHub CLI to create branches and pull requests (`gh issue develop -c <issue_number>`).
198+
We welcome contributions to improve the project! Before you begin, please take a moment to review our [Contributing Guidelines](./CONTRIBUTING.md). These guidelines will help you understand the process for submitting new features, bug fixes, and other improvements.
196199

197200
## Job Creation
198201

SQLDumpRestoration.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## Restoring the Database from SQL Dump
2+
3+
We generally load a database backup from a JSON file by using the following command.
4+
5+
```
6+
docker-compose -f local.yml run --rm django python manage.py loaddata backup.json
7+
```
8+
9+
However, if the JSON file is particularly large (>1.5GB), Docker might struggle with this method. In such cases, you can use SQL dump and restore commands as an alternative.
10+
11+
### Steps for Using SQL Dump and Restore
12+
13+
1. Begin by starting only the PostgreSQL container. This prevents the Django container from making changes while the PostgreSQL container is starting up.
14+
15+
```
16+
docker-compose -f local.yml up postgres
17+
```
18+
19+
2. Find the container ID using `docker ps`, then enter the PostgreSQL container to execute commands.
20+
21+
```
22+
$ docker ps
23+
CONTAINER ID IMAGE COMMAND
24+
23d33f22cc43 sde_indexing_helper_production_postgres "docker-entrypoint.s…"
25+
26+
$ docker exec -it 23d33f22cc43 bash
27+
```
28+
29+
3. Create a connection to the database.
30+
31+
```
32+
psql -U <POSTGRES_USER> -d <POSTGRES_DB>
33+
```
34+
35+
**Note**:
36+
- For local deployment, refer to the `.envs/.local/.postgres` file for the `POSTGRES_USER` and `POSTGRES_DB` variables.
37+
- For production deployment, refer to the `.envs/.production/.postgres` file.
38+
39+
4. Ensure that the database `<POSTGRES_DB>` is empty. Here's an example:
40+
41+
```
42+
sde_indexing_helper-# \c
43+
You are now connected to database "sde_indexing_helper" as user "VnUvMKBSdk...".
44+
sde_indexing_helper-# \dt
45+
Did not find any relations.
46+
```
47+
48+
If the database is not empty, delete its contents to create a fresh database:
49+
50+
```
51+
sde_indexing_helper=# \c postgres //connect to a different database before dropping
52+
You are now connected to database "postgres" as user "VnUvMKBSdk....".
53+
postgres=# DROP DATABASE sde_indexing_helper;
54+
DROP DATABASE
55+
postgres=# CREATE DATABASE sde_indexing_helper;
56+
CREATE DATABASE
57+
58+
```
59+
60+
5. Transfer the backup SQL dump (`backup.sql`) from your local machine to the PostgreSQL container.
61+
62+
```
63+
docker cp /local/path/backup.sql 23d33f22cc43:/
64+
```
65+
66+
6. Import the SQL dump into the PostgreSQL container.
67+
68+
```
69+
psql -U <POSTGRES_USER> -d <POSTGRES_DB> -f backup.sql
70+
```
71+
72+
**Note**: To create a SQL dump of your PostgreSQL database, use the following command:
73+
74+
```
75+
pg_dump -U <POSTGRES_USER> -W -F p -f backup.sql <POSTGRES_DB>
76+
```
77+
78+
7. Bring up all containers at once, and create a superuser account for logging in.
79+
80+
```
81+
docker-compose -f local.yml up
82+
docker-compose -f local.yml run --rm django python manage.py createsuperuser
83+
```
84+
85+
8. Log in to the SDE Indexing Helper frontend to ensure that all data has been correctly populated in the UI.

0 commit comments

Comments
 (0)