diff --git a/.env b/.env index c5458bc..2d7a96a 100644 --- a/.env +++ b/.env @@ -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= + + diff --git a/docker-compose-backup.yml b/docker-compose-backup.yml new file mode 100644 index 0000000..a658dfc --- /dev/null +++ b/docker-compose-backup.yml @@ -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: ~ diff --git a/docker-compose-common.yml b/docker-compose-common.yml index 57e4801..c63c13d 100644 --- a/docker-compose-common.yml +++ b/docker-compose-common.yml @@ -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" @@ -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: ~ diff --git a/docker-compose-odoo.yml b/docker-compose-odoo.yml index acc111f..2394ae6 100644 --- a/docker-compose-odoo.yml +++ b/docker-compose-odoo.yml @@ -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 diff --git a/docker-compose-openmrs.yml b/docker-compose-openmrs.yml index 12bea30..db0a326 100644 --- a/docker-compose-openmrs.yml +++ b/docker-compose-openmrs.yml @@ -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 diff --git a/docker-compose-restore.yml b/docker-compose-restore.yml new file mode 100644 index 0000000..c3a2666 --- /dev/null +++ b/docker-compose-restore.yml @@ -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 diff --git a/scripts/docker-compose-files.txt b/scripts/docker-compose-files.txt index b23e48a..e05762e 100755 --- a/scripts/docker-compose-files.txt +++ b/scripts/docker-compose-files.txt @@ -2,3 +2,4 @@ docker-compose-common.yml docker-compose-odoo.yml docker-compose-openmrs.yml docker-compose-senaite.yml +docker-compose-backup.yml diff --git a/scripts/utils.sh b/scripts/utils.sh index 91ceed3..1b82716 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -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"