-
Notifications
You must be signed in to change notification settings - Fork 3
Handle recovery target #71
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7fec43d
Use stanza name instead of r (for repo)
l00ptr acaf58b
Handle recovery target when recovering from backup
l00ptr 4ae109c
Handle BackupID on restore
l00ptr 023a79f
Reformat test cases for pgbackrest check repo func
l00ptr 6b6d70f
Improve support for pgBackRest multi-repo
l00ptr 6ebc78c
Reword doc about stanza create command
l00ptr cdcbc4a
Reformat usage page with pandoc
l00ptr 14e1deb
Use variable to keep podName on e2e test
l00ptr 2c8f239
Enhance e2e tests with data insertion and restore verification
l00ptr 5b45192
Enable archiving on clusters created on e2e tests
l00ptr ce5f201
Document recovery target usage
l00ptr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,83 +7,82 @@ sidebar_position: 3 | |||||
| ## Create an instance with pgBackRest | ||||||
|
|
||||||
| The `examples` directory contains several pre-configured manifests | ||||||
| designed to work with [`kind`](https://kind.sigs.k8s.io/) | ||||||
| (Eg: the pull policy is set to `Never`). | ||||||
| These files may require modifications to run on other types of | ||||||
| Kubernetes clusters. | ||||||
| designed to work with [`kind`](https://kind.sigs.k8s.io/) (Eg: the pull | ||||||
| policy is set to `Never`). These files may require modifications to run | ||||||
| on other types of Kubernetes clusters. | ||||||
|
|
||||||
| To use this plugin with a `Cluster`, CloudNativePG users must : | ||||||
|
|
||||||
| 1. Create a secret named `pgbackrest-s3-secret` in the namespace of the | ||||||
| PostgreSQL `Cluster`. This secret must contain the `key` and | ||||||
| `secret-key` of the `s3` bucket. | ||||||
|
|
||||||
| Example: | ||||||
|
|
||||||
| ```yaml title="secret.yaml" | ||||||
| --- | ||||||
| apiVersion: v1 | ||||||
| kind: Secret | ||||||
| metadata: | ||||||
| name: pgbackrest-s3-secret | ||||||
| type: Opaque | ||||||
| stringData: | ||||||
| ACCESS_KEY_ID: <key_to_replace> | ||||||
| ACCESS_SECRET_KEY: <secret_to_replace> | ||||||
| ``` | ||||||
|
|
||||||
| 2. Create a pgBackRest `stanza` : | ||||||
|
|
||||||
| Example: | ||||||
|
|
||||||
| ```yaml title="stanza.yaml" | ||||||
| --- | ||||||
| apiVersion: pgbackrest.dalibo.com/v1 | ||||||
| kind: Stanza | ||||||
| metadata: | ||||||
| name: stanza-sample | ||||||
| spec: | ||||||
| stanzaConfiguration: | ||||||
| name: main | ||||||
| s3Repositories: | ||||||
| - bucket: demo | ||||||
| endpoint: s3.minio.svc.cluster.local | ||||||
| region: us-east-1 | ||||||
| repoPath: /cluster-demo | ||||||
| uriStyle: path | ||||||
| verifyTLS: false | ||||||
| retentionPolicy: | ||||||
| full: 7 | ||||||
| fullType: count | ||||||
| diff: 14 | ||||||
| archive: 2 | ||||||
| archiveType: full | ||||||
| history: 30 | ||||||
| secretRef: | ||||||
| accessKeyId: | ||||||
| name: pgbackrest-s3-secret | ||||||
| key: ACCESS_KEY_ID | ||||||
| secretAccessKey: | ||||||
| name: pgbackrest-s3-secret | ||||||
| key: ACCESS_SECRET_KEY | ||||||
| ``` | ||||||
|
|
||||||
| :::note | ||||||
| The `s3Repositories` variable is a list. You can | ||||||
| configure multiple repositories. You can then select the repository to | ||||||
| which your backup will be performed. By default : | ||||||
| * the first repository is selected for backup ; | ||||||
| * WAL archiving always occurs on all repositories. | ||||||
| ::: | ||||||
|
|
||||||
| 3. Create the PostgreSQL `Cluster` and adapt the manifest by : | ||||||
| * adding the plugin definition `pgbackrest.dalibo.com` under the | ||||||
| `plugins` entry; | ||||||
| * referencing the pgBackRest `stanza` resource with `stanzaRef`. | ||||||
| 1. Create a `Secret` named `pgbackrest-s3-secret` in the namespace of | ||||||
| the PostgreSQL `Cluster`. This secret must contain the `key` and | ||||||
| `secret-key` of the `s3` bucket. | ||||||
|
|
||||||
| Example: | ||||||
|
|
||||||
| ```yaml title="cluster.yaml" | ||||||
| ``` yaml | ||||||
| --- | ||||||
| apiVersion: v1 | ||||||
| kind: Secret | ||||||
| metadata: | ||||||
| name: pgbackrest-s3-secret | ||||||
| type: Opaque | ||||||
| stringData: | ||||||
| ACCESS_KEY_ID: <key_to_replace> | ||||||
| ACCESS_SECRET_KEY: <secret_to_replace> | ||||||
| ``` | ||||||
|
|
||||||
| 2. Create a pgBackRest `stanza` : | ||||||
|
|
||||||
| Example: | ||||||
|
|
||||||
| ``` yaml | ||||||
l00ptr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| --- | ||||||
| apiVersion: pgbackrest.dalibo.com/v1 | ||||||
| kind: Stanza | ||||||
| metadata: | ||||||
| name: stanza-sample | ||||||
| spec: | ||||||
| stanzaConfiguration: | ||||||
| name: main | ||||||
| s3Repositories: | ||||||
| - bucket: demo | ||||||
| endpoint: s3.minio.svc.cluster.local | ||||||
| region: us-east-1 | ||||||
| repoPath: /cluster-demo | ||||||
| uriStyle: path | ||||||
| verifyTLS: false | ||||||
| retentionPolicy: | ||||||
| full: 7 | ||||||
| fullType: count | ||||||
| diff: 14 | ||||||
| archive: 2 | ||||||
| archiveType: full | ||||||
| history: 30 | ||||||
| secretRef: | ||||||
| accessKeyId: | ||||||
| name: pgbackrest-s3-secret | ||||||
| key: ACCESS_KEY_ID | ||||||
| secretAccessKey: | ||||||
| name: pgbackrest-s3-secret | ||||||
| key: ACCESS_SECRET_KEY | ||||||
| ``` | ||||||
|
|
||||||
| :::note The `s3Repositories` variable is a list. You can configure | ||||||
| multiple repositories. You can then select the repository to which your | ||||||
| backup will be performed. By default : | ||||||
|
|
||||||
| - the first repository is selected for backup ; | ||||||
| - WAL archiving always occurs on all repositories. ::: | ||||||
|
|
||||||
| 3. Create the PostgreSQL `Cluster` and adapt the manifest by : | ||||||
|
|
||||||
| - adding the plugin definition `pgbackrest.dalibo.com` under the | ||||||
| `plugins` entry; | ||||||
| - referencing the pgBackRest `stanza` resource with `stanzaRef`. | ||||||
|
|
||||||
| Example: | ||||||
|
|
||||||
| ``` yaml | ||||||
| --- | ||||||
| apiVersion: postgresql.cnpg.io/v1 | ||||||
| kind: Cluster | ||||||
|
|
@@ -100,24 +99,96 @@ spec: | |||||
| size: 1Gi | ||||||
| ``` | ||||||
|
|
||||||
| If it runs without errors, the `Pod` dedicated to the PostgreSQL `Cluster` | ||||||
| should have now two containers. One for the `postgres` service (which is | ||||||
| the default setup), an other one for the pgbackrest plugin, named | ||||||
| `pgbackrest-plugin`. The injected container now holds the responsibility | ||||||
| for archiving the WALs and triggering backups when a backup request is | ||||||
| made. | ||||||
| If it runs without errors, the `Pod` dedicated to the PostgreSQL | ||||||
| `Cluster` should have now two containers. One for the `postgres` service | ||||||
| (which is the default setup), an other one for the pgbackrest plugin, | ||||||
| named `pgbackrest-plugin`. The injected container now holds the | ||||||
| responsibility for archiving the WALs and triggering backups when a | ||||||
| backup request is made. | ||||||
|
|
||||||
| ## Stanza Initialization | ||||||
l00ptr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| Stanzas are initialized when archiving the first WAL. Since the stanza | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| initialization state is tracked internally, restarting the sidecar | ||||||
| container will require running the `pgbackrest create-stanza` command | ||||||
| container will cause the `pgbackrest create-stanza` command to run | ||||||
| again. | ||||||
|
|
||||||
| Adding a new repository to a stanza can require running the | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| `create-stanza` command again. Currently, this is not done | ||||||
| automatically. Restarting the `pgbackrest-plugin` container will launch | ||||||
| the create-stanza command. | ||||||
|
Collaborator
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.
Suggested change
|
||||||
|
|
||||||
| ## WAL Archiving | ||||||
|
|
||||||
| WAL archiving can be customized through the `pgbackrest` CRD. It is | ||||||
| possible to define the WAL archiving strategy (e.g. [using the | ||||||
| `asynchronous` | ||||||
| mode](https://pgbackrest.org/configuration.html#section-archive/option-archive-async)) | ||||||
| as well as configure the `pgbackrest` queue size. | ||||||
|
|
||||||
| ## Restoring a Cluster | ||||||
|
|
||||||
| To restore a `Cluster` from a backup, create a new `Cluster` that | ||||||
| references the `Stanza` containing the backup. Below is an example: | ||||||
|
|
||||||
| ``` yaml | ||||||
| --- | ||||||
| apiVersion: postgresql.cnpg.io/v1 | ||||||
| kind: Cluster | ||||||
| metadata: | ||||||
| name: cluster-restored | ||||||
| spec: | ||||||
| instances: 1 | ||||||
| plugins: | ||||||
| - name: pgbackrest.dalibo.com | ||||||
| parameters: | ||||||
| stanzaRef: stanza-sample | ||||||
| storage: | ||||||
| size: 1Gi | ||||||
| bootstrap: | ||||||
| recovery: | ||||||
| source: origin | ||||||
| externalClusters: | ||||||
| - name: origin | ||||||
| plugin: | ||||||
| name: pgbackrest.dalibo.com | ||||||
| parameters: | ||||||
| stanzaRef: stanza-sample | ||||||
| ``` | ||||||
|
|
||||||
| When using the recovery options, the `recoveryTarget` can be specified | ||||||
| to perform point-in-time recovery using a specific strategy (based on | ||||||
| time, LSN, etc.). If it is not specified, the recovery will continue up | ||||||
| to the latest available WAL. | ||||||
|
|
||||||
| ``` yaml | ||||||
| --- | ||||||
| apiVersion: postgresql.cnpg.io/v1 | ||||||
| kind: Cluster | ||||||
| metadata: | ||||||
| name: cluster-restored | ||||||
| spec: | ||||||
| instances: 1 | ||||||
| plugins: | ||||||
| - name: pgbackrest.dalibo.com | ||||||
| parameters: | ||||||
| stanzaRef: stanza-sample | ||||||
| storage: | ||||||
| size: 1Gi | ||||||
| bootstrap: | ||||||
| recovery: | ||||||
| source: origin | ||||||
| recoveryTarget: | ||||||
| backupID: 20260210-101333F | ||||||
| externalClusters: | ||||||
| - name: origin | ||||||
| plugin: | ||||||
| name: pgbackrest.dalibo.com | ||||||
| parameters: | ||||||
| stanzaRef: stanza-sample | ||||||
| ``` | ||||||
|
|
||||||
| If no specific backup (BackupID) is specified, the plugin lets | ||||||
| pgBackRest automatically choose the optimal backup using its standard | ||||||
| algorithm. For more details, see the [pgBackRest restore | ||||||
l00ptr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| documentation](https://pgbackrest.org/command.html#command-restore). | ||||||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.