Skip to content

Commit

Permalink
[#64] db parity tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mjstealey committed Mar 8, 2024
1 parent 9d11bc3 commit 181b95b
Show file tree
Hide file tree
Showing 3 changed files with 760 additions and 1 deletion.
42 changes: 42 additions & 0 deletions docs/backup-and-restore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Backup and Restore database

Commands used relate to full docker based deployment

## Backup

### `db_export.py` script

The `db_export.py` file defines a full model backup for all database tables for the version it has been specified for and should be used for periodic backups.

At times the data model may change in anticipation of a new release. When this happens the updated `db_export.py` file should be pushed to the running container prior to backup.

```
docker cp server/swagger_server/backup/utils/db_export.py api-flask-server:/code/server/swagger_server/backup/utils/db_export.py
```

### run script from the container

Exec onto the running container

```
docker exec -ti api-flask-server /bin/bash
```

Run the backup script which saves database tables as json file

```
source .env
source .venv/bin/activate
python -m server.swagger_server.backup.utils.db_export
exit
```

Copy the backup files to the local filesystem

```
docker cp api-flask-server:/code/server/swagger_server/backup/data .
```

A copy of the `data` directory will now be locally available.

## Restore
2 changes: 1 addition & 1 deletion server/swagger_server/backup/utils/db_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from swagger_server.response_code.core_api_utils import normalize_date_to_utc

# API version of data to restore from
api_version = '1.6.0'
api_version = '1.6.1'

# relative to the top level of the repository
BACKUP_DATA_DIR = os.getcwd() + '/server/swagger_server/backup/data'
Expand Down
Loading

0 comments on commit 181b95b

Please sign in to comment.