Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OZ-331: Add backup and restore support #121

Merged
merged 8 commits into from
Nov 26, 2024
Merged

OZ-331: Add backup and restore support #121

merged 8 commits into from
Nov 26, 2024

Conversation

enyachoke
Copy link
Contributor

@enyachoke enyachoke commented Nov 7, 2024

This PR introduces backup and restore support for Ozone powered by Restic and a custom wrapper project to allow us to use Docker Labels to enable backup and restore.

The project has two services ;

  • Backup Service (Enabled by default)
  • The restore service, which can be run on time to restore from a backup generated by the backup service

Backup and Restore when using the Ozone helper scripts

These instructions assume you are already in the Ozone Scripts directory --> see the start Documentation

Backup to Local Path

export BACKUP_PATH=/tmp/backup

./start.sh

Backup to S3

To setup the S3 bucket and user following the instructions in the Restic docs
Export the required ENVs

export AWS_ACCESS_KEY_ID='secret' 
export AWS_SECRET_ACCESS_KEY='secret' 
export RESTIC_REPOSITORY='s3:s3.amazonaws.com/ozone-dev-backup'
export AWS_DEFAULT_REGION='eu-west-1'

Run the start script
./start.sh

Restoring

Restoring from Local path

Export the required ENVs

export BACKUP_PATH=/tmp/backup
export COMPOSE_PROFILES='openmrs-restore,odoo-restore'
export RESTORE="true"

Run the start script
./start.sh

Restoring from S3

Export the required ENVs

export AWS_ACCESS_KEY_ID='secret' 
export AWS_SECRET_ACCESS_KEY='secret' 
export RESTIC_REPOSITORY='s3:s3.amazonaws.com/ozone-dev-backup'
export AWS_DEFAULT_REGION='eu-west-1'
export COMPOSE_PROFILES='openmrs-restore,odoo-restore'
export RESTORE="true"

Run the start script
./start.sh

Restic provides a rich set of features and a backup storage backend, but this PR supports only a small subset of the features and local path and S3 for the backup storage backend.

** Supported Configuration **

Env Variable Details Example
RESTIC_REPOSITORY Location of repository. A repository in Restic is refers to where the backups will be stored /restic-backups , s3:s3.amazonaws.com/ozone-dev-backup
RESTIC_PASSWORD The password used to unlock the repository
CRON_SCHEDULE Unix Cron pattern for when the backup with happen */5 * * * *
AWS_DEFAULT_REGION This is used to set the bucket region when RESTIC_REPOSITORY is S3
AWS_ACCESS_KEY_ID This is used to set the AWS access key id when RESTIC_REPOSITORY is S3
AWS_SECRET_ACCESS_KEY This is used to set the AWS secret when RESTIC_REPOSITORY is S3
RESTORE This variable is only needed when you want to test the restore using the start.sh helper script. It has to be set to true export RESTORE="true"
COMPOSE_PROFILES Along side env above, you have to enable the restore Docker compose profiles for the services you wish to restore when running with the start.sh export COMPOSE_PROFILES=openmrs-restore,odoo-restore
RESTIC_KEEP_WEEKLY How many weeks back we should keep at least one snapshot
RESTIC_KEEP_MONTHLY How many months back we should keep at least one snapshot
RESTIC_KEEP_YEARLY How many years back we should keep at least one snapshot
LOG_LEVEL The log level for the Docker Compose Wrapper info
RESTIC_LOCAL_BACKUP_PATH The external directory for storing restic backups when storing the backups on the local disk

Ticket --> https://mekomsolutions.atlassian.net/browse/OZ-331

@enyachoke enyachoke requested a review from rbuisson November 7, 2024 06:03
@enyachoke enyachoke requested a review from rbuisson November 14, 2024 13:49
scripts/utils.sh Outdated Show resolved Hide resolved
.env Outdated
# Backup path for local restic repository
BACKUP_PATH=


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove that last extra line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbuisson done

@enyachoke enyachoke requested a review from rbuisson November 25, 2024 09:47
@enyachoke enyachoke merged commit 7949fc2 into main Nov 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants