Repository navigation
Feature/71 db backup restore - #99
Merged
Merged
Conversation
9 of 13 tasks
anis022
requested changes
Dec 4, 2026
| /// </summary> | ||
| public async Task WriteFileAsync(string path, byte[] content) | ||
| { | ||
| await ShellAsync($"mkdir -p {Path.GetDirectoryName(path)}"); |
Member
There was a problem hiding this comment.
Path.GetDirectoryName(path) returns a Windows path on Windows (\tmp\local), so the mkdir inside the container fails. 4 backup tests fail with dotnet test on Windows (Restore_RestoresALocalFile and 3 others). I'll push a fix that builds the Linux path by hand.
Build the folder of a container path at the last '/' instead of with Path.GetDirectoryName, which gives backslashes on Windows, and send shell commands with \n line endings, since a Windows checkout gives the test files \r\n line endings that bash refuses.
anis022
approved these changes
Dec 4, 2026
anis022
approved these changes
Dec 4, 2026
anis022
left a comment
Member
There was a problem hiding this comment.
Pushed the fix. There was a second Windows issue too: multi-line shell commands in the tests get \r\n line endings on a Windows checkout and bash refuses them, so ShellAsync now converts them to \n. All 39 backup tests pass on Windows now.
6 tasks done
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #71
Overview
First of two PRs for #71 (database backup and restore). As agreed with Anis, this PR does everything that can be done without Azure. The Azure deployment (daily schedule, real storage, alert, restore test of a production backup) will come in a second PR once #12 is done.
The backup script (
infra/db-backup/backup.sh) dumps the database with pg_dump, counts the rows of every table, encrypts everything with age and a public key, computes a checksum and uploads both files to Blob Storage. Then it deletes the backups older than the retention. The purge only runs after a successful upload, so a failing job never deletes the last good backups.The restore script (
infra/db-backup/restore.sh) downloads a backup, checks its checksum, decrypts it, then restores it in a single transaction and checks that every table has the same number of rows as when it was backed up. It refuses a database that is not empty unless--confirmis given, and it only touches the target database after all the other checks passed.Both scripts run in a Docker image (
infra/db-backup/Dockerfile) and read their settings from environment variables only. Procedures, settings, measured time and the Azure plan are indocs/azure/backup-restore.md.What this PR covers from the acceptance criteria:
Partly done:
Not done here: the daily schedule, it needs the Container Apps Job from the second PR.
Testing
39 new integration tests in
tests/MoissonMontreal.Tests/DbBackup/, run withdotnet test. They use Testcontainers to start PostgreSQL, Azurite (Blob Storage emulator) and the backup image itself, so they test the same image that will run in Azure.dotnet test --filter "FullyQualifiedName~MoissonMontreal.Tests.DbBackup"The first run downloads the Azurite image and builds the backup image, so it takes a few minutes. After that, the 39 tests take about 15 seconds.
Fixtures/BackupTestData.sql(10,000 receipts, 50,000 receipt lines, 39 MB)./healthon the restored database.Full test suite: 789 passed, 0 failed, 0 warnings. Measured: backup 0.4 s, restore 0.6 s for 39 MB.
Screenshots / Screencasts
N/A, no frontend changes.
Checklist
Notes
BACKUP_RETENTION_DAYS) until Moisson Montréal confirms it.infra/db-backup/, next to theinfra/folder of PR feat(infra): add Azure App Service and PostgreSQL manual deployment #58. Both PRs add a section at the end ofREADME.md, so the second one merged will have a small conflict: keep both sections.Testcontainers.Azurite(same version asTestcontainers.PostgreSql) andAzure.Storage.Blobsto the test project, for the Blob Storage emulator.