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

Backup and restore from s3 bucket #3640

Merged
merged 3 commits into from
Sep 30, 2023

Conversation

BacLuc
Copy link
Contributor

@BacLuc BacLuc commented Jul 31, 2023

How to create and upload the backup was inspired from here: https://github.com/itbm/postgresql-backup-s3/blob/master/backup.sh

How to encrypt/decrypt de backup was inspired by here: https://www.cyberciti.biz/tips/linux-how-to-encrypt-and-decrypt-files-with-a-password.html

To decrypt the backup:
gpg --passphrase=${ENCRYPTION_KEY} --batch -d backup.sql.gz.gpg > backup.sql.gz; gunzip backup.sql.gz

Chose to use a workflow_dispatch instead of a cronjob to start a little simpler.
Because we need to migrate the database after the restore (because we load old data in a potentially newer codebase),
the restore is implemented with a helm hook.

Please review carefully, because we can only start to test the workflows when they are merged.
Could test it thoroughly on my fork: #3478 (comment)

Issue: #3478

@BacLuc BacLuc force-pushed the backup-and-restore-from-s3-bucket branch from 9ddc631 to d496297 Compare July 31, 2023 16:41
@BacLuc BacLuc added the deploy! Creates a feature branch deployment for this PR label Jul 31, 2023
@BacLuc BacLuc temporarily deployed to feature-branch July 31, 2023 16:50 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Jul 31, 2023

Feature branch deployment currently inactive.

If the PR is still open, you can add the deploy! label to this PR to trigger a feature branch deployment.

@BacLuc BacLuc mentioned this pull request Jul 31, 2023
@BacLuc BacLuc removed the deploy! Creates a feature branch deployment for this PR label Jul 31, 2023
@BacLuc BacLuc linked an issue Aug 19, 2023 that may be closed by this pull request
@BacLuc BacLuc force-pushed the backup-and-restore-from-s3-bucket branch from d496297 to a97eebb Compare August 20, 2023 18:41
@carlobeltrame carlobeltrame temporarily deployed to pr3730 August 20, 2023 18:55 Destroyed
@carlobeltrame carlobeltrame temporarily deployed to pr3730 August 20, 2023 19:43 Destroyed
@carlobeltrame carlobeltrame temporarily deployed to pr3730 August 20, 2023 19:50 Destroyed
@carlobeltrame carlobeltrame temporarily deployed to pr3730 August 20, 2023 20:03 Destroyed
@carlobeltrame carlobeltrame temporarily deployed to pr3730 August 20, 2023 20:16 Destroyed
@carlobeltrame carlobeltrame temporarily deployed to pr3730 August 20, 2023 20:38 Destroyed
@BacLuc BacLuc marked this pull request as draft August 20, 2023 20:53
@BacLuc
Copy link
Contributor Author

BacLuc commented Aug 20, 2023

Session with @pmattmann showed:
the empty-dir volume between the containers is not synced reliably -> switch to one image to rule them all.

@carlobeltrame carlobeltrame temporarily deployed to pr3732 August 22, 2023 11:28 Destroyed
@carlobeltrame carlobeltrame temporarily deployed to pr3732 August 22, 2023 11:34 Destroyed
@BacLuc BacLuc force-pushed the backup-and-restore-from-s3-bucket branch from a97eebb to e8ccd4c Compare September 12, 2023 14:12
@BacLuc
Copy link
Contributor Author

BacLuc commented Sep 12, 2023

Redid the implementation now with an image, after #3640 (comment)
Test plan with results is here: #3478 (comment)

I will rebase onto devel and update the github actions in the moved workflow files as soon as i have review

@BacLuc BacLuc marked this pull request as ready for review September 12, 2023 14:15
type: string
description: |
The sourceFile of the backup in the bucket to restore, e.g.
ecamp3-dev/2023-07-17-12-55-33-ecamp3-dev.sql.gz.gpg
Copy link
Member

Choose a reason for hiding this comment

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

How will we know what to enter here? Is it possible to mistakenly restore prod on dev this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only for dev and pr, and on dev you don't have the access rights and the encryption key to use a prod or staging backup

@@ -8,3 +8,19 @@ POSTGRES_ADMIN_URL=
BASIC_AUTH_ENABLED=false
BASIC_AUTH_USERNAME=test
BASIC_AUTH_PASSWORD=test

BACKUP_SCHEDULE=@hourly
Copy link
Member

Choose a reason for hiding this comment

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

Is that the default? Isn't that a bit much? One prod backup is around 16MB right now, but on eCamp v2 a prod dump is roughly 1GB.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just if you want to deploy the containers and the helm chart from your local machine.
The problem is shell globbing, which turns your cron expression "2 * * * *" into "2 ...".
But for my tests i even set it to all 3 minutes, because i don't want to wait that long for the job to execute, and i don't leave the deployment up for long.

The prod backup we used on the last hackaton ist 2.4 MB compressed.

BACKUP_ENCRYPTION_KEY=test

#RESTORE_SOURCE_FILE=latest
RESTORE_SOURCE_APP=${instance_name}-1
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why you chose this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the deploy script also allows to deploy the helm chart multiple times in one go.
That's why the deployment app name is in my case bacluc-1.
But we could also remove the value here, because then it uses the app name generated in the chart

.helm/ecamp3/files/db_backup_job/.env-example Show resolved Hide resolved
api/migrations/schema/Version20230409164830.php Outdated Show resolved Hide resolved
Copy link
Member

@carlobeltrame carlobeltrame left a comment

Choose a reason for hiding this comment

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

Did a session with @BacLuc and he was able to answer all my conceptual questions.

@BacLuc BacLuc force-pushed the backup-and-restore-from-s3-bucket branch from e8ccd4c to 960f60b Compare September 30, 2023 14:51
@BacLuc
Copy link
Contributor Author

BacLuc commented Sep 30, 2023

this was the rebase force push

@BacLuc
Copy link
Contributor Author

BacLuc commented Sep 30, 2023

this was the rebase force push

sorry, this force push was a fail

@BacLuc BacLuc force-pushed the backup-and-restore-from-s3-bucket branch from 960f60b to a674d57 Compare September 30, 2023 15:14
@BacLuc BacLuc force-pushed the backup-and-restore-from-s3-bucket branch from a674d57 to 84eb548 Compare September 30, 2023 15:15
@BacLuc
Copy link
Contributor Author

BacLuc commented Sep 30, 2023

@BacLuc BacLuc added this pull request to the merge queue Sep 30, 2023
Merged via the queue into ecamp:devel with commit c814a15 Sep 30, 2023
28 checks passed
@BacLuc BacLuc mentioned this pull request Sep 30, 2023
@BacLuc BacLuc deleted the backup-and-restore-from-s3-bucket branch December 23, 2023 19:13
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.

Possibility to reset data of dev.ecamp3.ch deployment
3 participants