-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CU-8692nw7qj: backup and restore scripts, re-organise shell scripts, …
…docs describing these funcs
- Loading branch information
1 parent
2412349
commit feede11
Showing
14 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Maintanence | ||
|
||
MedCATtrainer is actively maintained. To ensure you receive the latest | ||
security patches of the software and its dependencies you should regularly | ||
be upgrading to the latest release. | ||
|
||
The latest stable releases update the `docker-compose.yml` and `docker-compose-prod.yml` files. | ||
|
||
To update these docker compose files, either copy them directly from the [repo](https://github.com/CogStack/MedCATtrainer) | ||
or update the cloned files via: | ||
|
||
```shell | ||
$ cd MedCATtrainer | ||
$ git pull | ||
$ docker-compose up | ||
# alternatively for prod releases use: | ||
$ docker-compose -f docker-compose-prod.yml up | ||
``` | ||
|
||
MedCATtrainer follows [Semver](https://semver.org/), so patch and minor release should always be backwards compatible, | ||
whereas major releases, e.g. v1.x vs 2.x versions signify breaking changes. | ||
|
||
Neccessary Django DB migrations will automatically applied between releases, which should largely be invisible to an end admin | ||
or annotation user. Nevertheless, migrating ORM / DB models, then rolling back a release can cause issues if values are defaulted | ||
or removed from a later version. | ||
|
||
## Backup and Restore | ||
|
||
Before updating to a new release, a backup will be created in the `DB_BACKUP_DIR`, as configured in `envs/env`. | ||
|
||
This is automatically done each time the service starts, and any migrations are performed, in the events of a new release | ||
for example. | ||
|
||
If a DB is corrupted or needs to be restored to an existing backed up db use the following commands, whilst the service is running: | ||
|
||
```shell | ||
$ docker ps | ||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | ||
a2489b0c681b cogstacksystems/medcat-trainer-nginx:v2.11.2 "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp, 0.0.0.0:8001->8000/tcp, :::8001->8000/tcp medcattrainer-nginx-1 | ||
20fed153d798 solr:8 "docker-entrypoint.s…" 4 days ago Up 4 days 0.0.0.0:8983->8983/tcp, :::8983->8983/tcp mct_solr | ||
2b250a0975fe cogstacksystems/medcat-trainer:v2.11.2 "/home/run.sh" 4 days ago Up 4 days medcattrainer-medcattrainer-1 | ||
$ docker exec -it 2b250a0975fe bash | ||
root@2b250a0975fe:/home/api# cd .. | ||
$ restore_db.sh db-backup-2023-09-25__23-21-39.sqlite3 # run the restore.sh script | ||
Found backup dir location: /home/api/db-backup, found db path: home/api/db/db.sqlite3 | ||
DB file to restore: db-backup-2023-09-25__23-21-39.sqlite3 | ||
Found db-backup-2023-09-25__23-21-39.sqlite3 - y to confirm backup: y # you'll need tp confirm this is the correct file to restore. | ||
Restored db-backup-2023-09-25__23-21-39.sqlite3 to /home/db/db.sqlite3 | ||
``` | ||
|
||
The `restore_db.sh` scipt will automatically restore the latest db file, if no file is specified. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
if [ -n "${DB_BACKUP_DIR}" ] && [ -f "${DB_PATH}" ]; then | ||
echo "Found backup dir location: ${DB_BACKUP_DIR} and DB_PATH: ${DB_PATH}" | ||
if [ ! -d "${DB_BACKUP_DIR}" ]; then | ||
mkdir DB_BACKUP_DIR | ||
fi | ||
BACKUP_NAME=db-backup-$(date +"%Y-%m-%d__%H-%M-%S").sqlite3 | ||
cp $DB_PATH ${DB_BACKUP_DIR}/${BACKUP_NAME} | ||
echo "Backed up existing DB to ${DB_BACKUP_DIR}/${BACKUP_NAME}" | ||
echo "To restore this backup use $ /home/scripts/restore.sh ${DB_BACKUP_DIR}/${BACKUP_NAME}" | ||
else | ||
echo "No DB_BACKUP_DIR env var found or DB_PATH . This should be set in env vars. No backups will be created" | ||
return 0 | ||
fi | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
DB_RESTORE_FILE=$1 | ||
BACKUP_DIR=${DB_BACKUP_DIR} | ||
|
||
if [ -n "$BACKUP_DIR" ] && [ -n "$DB_PATH" ]; then | ||
echo "Found backup dir location: ${BACKUP_DIR}, found db path: ${DB_PATH}" | ||
if [ -z "$DB_RESTORE_FILE" ]; then | ||
echo "No specific backup specified. Restoring latest backup in $BACKUP_DIR" | ||
DB_RESTORE_FILE=$(ls -Art ${BACKUP_DIR}/ | tail -n 1) | ||
fi | ||
echo "DB file to restore: ${DB_RESTORE_FILE}" | ||
read -p "Found $DB_RESTORE_FILE - y to confirm backup: " choice | ||
case "$choice" in | ||
y|Y ) | ||
cp $BACKUP_DIR/$DB_RESTORE_FILE $DB_PATH | ||
echo "Restored $DB_RESTORE_FILE to $DB_PATH" | ||
;; | ||
n|N ) | ||
echo " - exiting";; | ||
* ) | ||
echo "Invalid choice - exiting";; | ||
esac | ||
else | ||
echo "No BACKUP_DIR and DB_PATH found. Set to location of the backups and the location of DB sqlite3 file to be restored." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters