Skip to content

Commit

Permalink
OZ-331: Add backup and restore support
Browse files Browse the repository at this point in the history
  • Loading branch information
enyachoke committed Nov 7, 2024
1 parent d703ff4 commit beb65a2
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,30 @@ ODOO_HOSTNAME=erp-172-17-0-1.traefik.me
SENAITE_HOSTNAME=lims-172-17-0-1.traefik.me
ERPNEXT_HOSTNAME=erpnext-172-17-0-1.traefik.me
FHIR_ODOO_HOSTNAME=fhir-erp-172-17-0-1.traefik.me

#
# Backup
#
RESTIC_REPOSITORY=/restic_data

# Used to encrypt the restic repository
RESTIC_PASSWORD=password
RESTIC_RESTORE_SNAPSHOT=latest

RESTIC_KEEP_DAILY=7
RESTIC_KEEP_WEEKLY=4
RESTIC_KEEP_MONTHLY=12
RESTIC_KEEP_YEARLY=3

LOG_LEVEL=info
CRON_SCHEDULE=*/5 * * * *

# Amazon S3 access (Provide if RESTIC_REPOSITORY points to an S3 bucket)
AWS_DEFAULT_REGION=eu-west-1
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# Backup path for local restic repository
RESTIC_LOCAL_BACKUP_PATH=


25 changes: 25 additions & 0 deletions docker-compose-backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
backup:
image: mekomsolutions/restic-compose-backup
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
# Map local restic repository
- ${RESTIC_LOCAL_BACKUP_PATH:-./restic_data}:/restic_data
# Map restic cache
- restic_cache:/cache
environment:
RESTIC_REPOSITORY: ${RESTIC_REPOSITORY}
RESTIC_PASSWORD: ${RESTIC_PASSWORD}
RESTIC_KEEP_DAILY: ${RESTIC_KEEP_DAILY}
RESTIC_KEEP_WEEKLY: ${RESTIC_KEEP_WEEKLY}
RESTIC_KEEP_MONTHLY: ${RESTIC_KEEP_MONTHLY}
RESTIC_KEEP_YEARLY: ${RESTIC_KEEP_YEARLY}
LOG_LEVEL: ${LOG_LEVEL}
CRON_SCHEDULE: ${CRON_SCHEDULE}
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
networks:
- ozone
volumes:
restic_cache: ~
4 changes: 4 additions & 0 deletions docker-compose-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ services:
volumes:
- "${MYSQL_DATADIR:-mysql-data}:/var/lib/mysql"
- "${SQL_SCRIPTS_PATH}/mysql/create_db.sh:/docker-entrypoint-initdb.d/create_db.sh"
labels:
restic-compose-backup.mariadb: true

postgresql:
command: "postgres -c wal_level=logical -c max_wal_senders=10 -c max_replication_slots=10"
Expand All @@ -58,6 +60,8 @@ services:
volumes:
- "${POSTGRES_DATADIR:-postgresql-data}:/var/lib/postgresql/data"
- "${SQL_SCRIPTS_PATH}/postgresql/create_db.sh:/docker-entrypoint-initdb.d/create_db.sh"
labels:
restic-compose-backup.postgres: true

volumes:
mysql-data: ~
Expand Down
4 changes: 4 additions & 0 deletions docker-compose-odoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ services:
traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto: https
traefik.http.middlewares.limit.buffering.memRequestBodyBytes: 20971520
traefik.http.middlewares.limit.buffering.maxRequestBodyBytes: 20971520

#=====================================================backup================================================================
restic-compose-backup.volumes: true
restic-compose-backup.volumes.include: "${ODOO_FILESTORE:-odoo-filestore},${ODOO_CONFIG_CHECKSUMS_PATH:-odoo-checksums}"
networks:
- ozone
- web
Expand Down
3 changes: 3 additions & 0 deletions docker-compose-openmrs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ services:
traefik.http.routers.openmrs.middlewares: openmrs-spa-redirectregex
traefik.http.middlewares.openmrs-spa-redirectregex.redirectregex.regex: https://${O3_HOSTNAME}/openmrs/spa
traefik.http.middlewares.openmrs-spa-redirectregex.redirectregex.replacement: https://${O3_HOSTNAME}/openmrs/spa/home
#=====================================================backup================================================================
restic-compose-backup.volumes: true
restic-compose-backup.volumes.include: "${OPENMRS_CONFIG_CHECKSUMS_PATH:-openmrs-config-checksums}"
networks:
- ozone
- web
Expand Down
32 changes: 32 additions & 0 deletions docker-compose-restore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
services:
openmrs:
depends_on:
restore:
condition: service_completed_successfully
profiles:
- openmrs-restore
odoo:
depends_on:
restore:
condition: service_completed_successfully
profiles:
- odoo-restore
backup:
depends_on:
restore:
condition: service_completed_successfully
restore:
image: mekomsolutions/restic-compose-backup-restore
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
# Map local restic repository
- ${RESTIC_LOCAL_BACKUP_PATH:-./restic_data}:/restic_data
environment:
RESTIC_REPOSITORY: ${RESTIC_REPOSITORY}
RESTIC_PASSWORD: ${RESTIC_PASSWORD}
LOG_LEVEL: ${LOG_LEVEL}
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
networks:
- ozone
1 change: 1 addition & 0 deletions scripts/docker-compose-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ docker-compose-common.yml
docker-compose-odoo.yml
docker-compose-openmrs.yml
docker-compose-senaite.yml
docker-compose-backup.yml
6 changes: 6 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ function setDockerComposeCLIOptions () {
export dockerComposeFilesCLIOptions="$dockerComposeFilesCLIOptions -f ../$file"
done

# Add restore file if restore env is set

if [ "$BACKUP_RESTORE" == "true" ]; then
export dockerComposeFilesCLIOptions="$dockerComposeFilesCLIOptions -f ../docker-compose-restore.yml"
fi

# Set the default env file
export dockerComposeEnvFilePath="../.env"

Expand Down

0 comments on commit beb65a2

Please sign in to comment.