Skip to content

Commit 71c8fb4

Browse files
author
Dawadi Kiran
committed
Fixes issue #993 - Add SQLDumpRestoration.md file
1 parent 4eb0b6d commit 71c8fb4

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

SQLDumpRestoration.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 VnUvMKBSdkoFIETgLongnxYHrYVJKufn -d sde_indexing_helper
33+
```
34+
35+
4. Ensure that the database `sde_indexing_helper` is empty.
36+
37+
```
38+
sde_indexing_helper-# \c
39+
You are now connected to database "sde_indexing_helper" as user "VnUvMKBSdk...".
40+
sde_indexing_helper-# \dt
41+
Did not find any relations.
42+
```
43+
44+
If the database is not empty, delete its contents to create a fresh database:
45+
46+
```
47+
sde_indexing_helper=# \c postgres
48+
You are now connected to database "postgres" as user "VnUvMKBSdkoFIETgLongnxYHrYVJKufn".
49+
postgres=# DROP DATABASE sde_indexing_helper;
50+
DROP DATABASE
51+
postgres=# CREATE DATABASE sde_indexing_helper;
52+
CREATE DATABASE
53+
54+
```
55+
56+
5. Transfer the backup SQL dump (`backup.sql`) from your local machine to the PostgreSQL container.
57+
58+
```
59+
docker cp /local/path/backup.sql 23d33f22cc43:/
60+
```
61+
62+
6. Import the SQL dump into the PostgreSQL container.
63+
64+
```
65+
psql -U VnUvMKBSdkoFIETgLongnxYHrYVJKufn -d sde_indexing_helper -f backup.sql
66+
```
67+
68+
**Note**: To create a SQL dump of your PostgreSQL database, use the following command:
69+
70+
```
71+
pg_dump -U VnUvMKBSdkoFIETgLongnxYHrYVJKufn -W -F p -f backup.sql sde_indexing_helper
72+
```
73+
74+
7. Bring up all containers at once, and create a superuser account for logging in.
75+
76+
```
77+
docker-compose -f local.yml up
78+
docker-compose -f local.yml run --rm django python manage.py createsuperuser
79+
```
80+
81+
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)