-
Notifications
You must be signed in to change notification settings - Fork 6
docs: clarify backup and restore coverage #72
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -322,6 +322,10 @@ The chart will automatically run database migrations before deploying the new ve | |
|
|
||
| ## Backup and restore | ||
|
|
||
| <Warning> | ||
| These steps cover PostgreSQL backups and restore. They do not automatically back up or restore uploaded files if your deployment stores them outside PostgreSQL. | ||
| </Warning> | ||
|
|
||
| ### PostgreSQL backups with CloudNativePG | ||
|
|
||
| CloudNativePG supports volume snapshot backups: | ||
|
|
@@ -352,14 +356,24 @@ kubectl exec -n sure $PRIMARY_POD -- pg_dump -U sure sure_production > backup.sq | |
|
|
||
| ### Restore from backup | ||
|
|
||
| 1. Make sure app traffic is stopped or the deployment is in maintenance mode. | ||
|
|
||
| 2. Copy the SQL backup to the primary PostgreSQL pod: | ||
|
|
||
| ```bash | ||
| # Copy backup to pod | ||
| kubectl cp backup.sql sure/$PRIMARY_POD:/tmp/backup.sql | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| ``` | ||
|
Comment on lines
+361
to
+365
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
FILE="$(fd '^self-hosting-helm\.mdx$' | head -n1)"
rg -n -C2 'PRIMARY_POD|kubectl cp backup\.sql|kubectl exec -n sure \$PRIMARY_POD' "$FILE"Repository: we-promise/docs Length of output: 536 🌐 Web query:
💡 Result: No, pod/ is not valid as the pod token in the kubectl cp file-spec [[namespace/]pod:]file/path. The pod token must be just (optionally prefixed by namespace/ if specifying a non-default namespace). The official Kubernetes documentation shows examples using :path for default namespace and /:path for specific namespaces, with no pod/ prefix. The source code parser in pkg/cmd/cp/cp.go splits the part before the colon (:) by / and accepts exactly 1 piece (PodName) or 2 pieces (PodNamespace/PodName). Three pieces like pod/ would result in more than 2, causing "filespec must match the canonical format: [[namespace/]pod:]file/path" error. All examples across docs, man pages, and tutorials consistently use or namespace/, never pod/. The pod/ prefix appears only in explanatory text like "pod token", not in actual syntax. Citations:
Fix Line 348 sets Extract only the pod name (without the Suggested doc patch-PRIMARY_POD=$(kubectl get pod -n sure -l cnpg.io/cluster=sure-db,role=primary -o name)
+PRIMARY_POD=$(kubectl get pod -n sure -l cnpg.io/cluster=sure-db,role=primary -o jsonpath='{.items[0].metadata.name}')🤖 Prompt for AI Agents |
||
|
|
||
| 3. Restore the database: | ||
|
|
||
| # Restore | ||
| ```bash | ||
| kubectl exec -n sure $PRIMARY_POD -- psql -U sure sure_production -f /tmp/backup.sql | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restoring a SQL dump into an existing database that already contains schema and data can lead to conflicts (e.g., |
||
| ``` | ||
|
|
||
| 4. If your deployment uses uploaded files stored outside PostgreSQL, restore those separately using the matching volume snapshot or object-storage recovery process. | ||
|
|
||
| 5. Verify that the app starts cleanly and your data appears as expected. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### View logs | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,20 @@ docker compose up --no-deps -d web worker | |
|
|
||
| The Docker Compose configuration includes an optional backup service that automatically backs up your PostgreSQL database. | ||
|
|
||
| <Warning> | ||
| The backup service only creates PostgreSQL backups. It does not back up local files stored in Sure's `storage` directory. | ||
| If your deployment uses local file storage, back up that directory separately. If you use external object storage such as S3 or R2, make sure that storage is protected with its own backup and retention policy. | ||
| </Warning> | ||
|
|
||
| ### What to back up | ||
|
|
||
| For a complete recovery plan, make sure you know which of these apply to your deployment: | ||
|
|
||
| - **PostgreSQL database**: accounts, transactions, settings, users, and metadata | ||
| - **Local file storage**: uploaded files stored on disk by the app | ||
| - **External object storage**: uploaded files stored in S3, R2, or another object store | ||
| - **Environment and deployment config**: your `.env`, `compose.yml`, secrets, and any reverse proxy or DNS setup needed to bring the app back online | ||
|
|
||
| ### Enabling backups | ||
|
|
||
| The backup service uses Docker Compose profiles and is disabled by default. To enable it: | ||
|
|
@@ -268,28 +282,56 @@ You can use cron syntax or these shortcuts: | |
| - `@monthly` - Once per month | ||
| - Custom cron: `0 2 * * *` (2 AM daily) | ||
|
|
||
| ### Restoring from backup | ||
| ### Restore from a PostgreSQL backup | ||
|
|
||
| To restore your database from a backup: | ||
| Use this process when you have a SQL dump created by the backup service or with `pg_dump`. | ||
|
|
||
| > [!NOTE] | ||
| > If you customized the PostgreSQL username, password, or database name in your `.env` or `compose.yml`, replace `sure_user` and `sure_production` in the commands below. | ||
|
|
||
| 1. Stop the application containers so they do not write to the database during the restore: | ||
|
|
||
| 1. Stop the application: | ||
| ```bash | ||
| docker compose down | ||
| docker compose stop web worker | ||
| ``` | ||
|
|
||
| 2. Locate your backup file in the backup directory (e.g., `/opt/sure-data/backups`) | ||
| 2. Start or keep the database container running: | ||
|
|
||
| 3. Restore the backup: | ||
| ```bash | ||
| docker compose up -d db | ||
| ``` | ||
|
|
||
| 3. Locate the backup file in your backup directory, for example `/opt/sure-data/backups`. | ||
|
|
||
| 4. Restore the SQL backup into PostgreSQL: | ||
|
|
||
| ```bash | ||
| docker compose exec -T db psql -U sure_user -d sure_production < /path/to/backup.sql | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ``` | ||
|
|
||
| 4. Restart the application: | ||
| 5. Restart the app: | ||
|
|
||
| ```bash | ||
| docker compose up -d | ||
| docker compose up -d web worker | ||
| ``` | ||
|
|
||
| ### Restore local uploaded files | ||
|
|
||
| If your Sure instance stores uploaded files on the local filesystem, restoring the database alone is not enough. You must also restore the app's storage directory from the matching file backup. | ||
|
|
||
| The exact host path depends on how you mapped volumes in `compose.yml`. Restore the same directory that Sure uses for local storage, then restart the app containers. | ||
|
|
||
|
Comment on lines
+312
to
+323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid conflicting restart order in restore flow. Line 315 restarts Suggested doc adjustment-5. Restart the app:
+5. If you are restoring only PostgreSQL, restart the app:
```bash
docker compose up -d web workerRestore local uploaded filesIf your Sure instance stores uploaded files on the local filesystem, restoring the database alone is not enough. You must also restore the app's storage directory from the matching file backup. -The exact host path depends on how you mapped volumes in If you are using external object storage instead of local disk, restore those files using that provider's backup or versioning workflow instead. Verify each finding against the current code and only fix it if needed. In |
||
| If you are using external object storage instead of local disk, restore those files using that provider's backup or versioning workflow instead. | ||
|
|
||
| ### Verify the restore | ||
|
|
||
| After restoring, check the following: | ||
|
|
||
| - You can sign in successfully | ||
| - Your accounts and transactions appear as expected | ||
| - Uploaded files open correctly, if you use uploads | ||
| - The web and worker containers start cleanly without repeated errors | ||
|
|
||
| ### Verifying backups | ||
|
|
||
| Check that backups are running correctly: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a more guided experience, it is helpful to provide the specific command to stop the application workloads. This ensures that no new data is written to the database during the restore process.
Example command: