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

Fix VolumeSnapshot backup capability #335

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions charts/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
| backups.google.bucket | string | `""` | |
| backups.google.gkeEnvironment | bool | `false` | |
| backups.google.path | string | `"/"` | |
| backups.provider | string | `"s3"` | One of `s3`, `azure` or `google` |
| backups.provider | string | `"s3"` | One of `s3`, `azure`, `google`, or `volumeSnapshot` |
| backups.retentionPolicy | string | `"30d"` | Retention policy for backups |
| backups.s3.accessKey | string | `""` | |
| backups.s3.bucket | string | `""` | |
| backups.s3.path | string | `"/"` | |
| backups.s3.region | string | `""` | |
| backups.s3.secretKey | string | `""` | |
| backups.scheduledBackups[0].backupOwnerReference | string | `"self"` | Backup owner reference |
| backups.scheduledBackups[0].method | string | `"barmanObjectStore"` | Backup method, can be `barmanObjectStore` (default) or `volumeSnapshot` |
| backups.scheduledBackups[0].name | string | `"daily-backup"` | Scheduled backup name |
| backups.scheduledBackups[0].schedule | string | `"0 0 0 * * *"` | Schedule in cron format |
| backups.secret.create | bool | `true` | Whether to create a secret for the backup credentials |
| backups.secret.name | string | `""` | Name of the backup credentials secret |
| backups.volumeSnapshot.className | string | `""` | The VolumeSnapshotClass to use for backups if provider is `volumeSnapshot` |
| backups.wal.compression | string | `"gzip"` | WAL compression method. One of `` (for no compression), `gzip`, `bzip2` or `snappy`. |
| backups.wal.encryption | string | `"AES256"` | Whether to instruct the storage provider to encrypt WAL files. One of `` (use the storage container default), `AES256` or `aws:kms`. |
| backups.wal.maxParallel | int | `1` | Number of WAL files to be archived or restored in parallel. |
Expand Down Expand Up @@ -206,7 +206,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
| recovery.google.bucket | string | `""` | |
| recovery.google.gkeEnvironment | bool | `false` | |
| recovery.google.path | string | `"/"` | |
| recovery.method | string | `"backup"` | Available recovery methods: * `backup` - Recovers a CNPG cluster from a CNPG backup (PITR supported) Needs to be on the same cluster in the same namespace. * `object_store` - Recovers a CNPG cluster from a barman object store (PITR supported). * `pg_basebackup` - Recovers a CNPG cluster viaa streaming replication protocol. Useful if you want to migrate databases to CloudNativePG, even from outside Kubernetes. # TODO |
| recovery.method | string | `"backup"` | Available recovery methods: * `backup` - Recovers a CNPG cluster from a CNPG backup (PITR supported) Needs to be on the same cluster in the same namespace. * `object_store` - Recovers a CNPG cluster from a barman object store (PITR supported). * `pg_basebackup` - Recovers a CNPG cluster viaa streaming replication protocol. Useful if you want to migrate databases to CloudNativePG, even from outside Kubernetes. * `volumeSnapshot` - Recovers a CNPG cluster from a volume snapshot. |
| recovery.pgBaseBackup.database | string | `"app"` | Name of the database used by the application. Default: `app`. |
| recovery.pgBaseBackup.owner | string | `""` | Name of the secret containing the initial credentials for the owner of the user database. If empty a new secret will be created from scratch |
| recovery.pgBaseBackup.secret | string | `""` | Name of the owner of the database in the instance to be used by applications. Defaults to the value of the `database` key. |
Expand Down Expand Up @@ -234,6 +234,8 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
| recovery.s3.secretKey | string | `""` | |
| recovery.secret.create | bool | `true` | Whether to create a secret for the backup credentials |
| recovery.secret.name | string | `""` | Name of the backup credentials secret |
| recovery.volumeSnapsnot.storageSnapshotName | string | "" | The name of the snapshot to recover from |
| recovery.volumeSnapsnot.walSnapshotName | string | "" | The name of the snapshot that holds the Write Ahead Log |
| type | string | `"postgresql"` | Type of the CNPG database. Available types: * `postgresql` * `postgis` |

## Maintainers
Expand Down
18 changes: 18 additions & 0 deletions charts/cluster/examples/backups-volume-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cluster:
instances: 1

storage:
# This storage class uses the CSI driver which allows for volume snapshots
storageClass: "my-storage-class"

backups:
enabled: true
provider: volumeSnapshot
volumeSnapshot:
# Points to our snapshot class, see https://kubernetes.io/docs/concepts/storage/volume-snapshot-classes/
className: "my-custom-snapshot-class"
scheduledBackups:
- name: daily-backup # Daily at midnight
schedule: "0 0 0 * * *" # Daily at midnight
backupOwnerReference: self
retentionPolicy: "30d"
14 changes: 14 additions & 0 deletions charts/cluster/examples/recovery-volume-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mode: recovery

cluster:
instances: 1
storage:
# This storage class uses the CSI driver which allows for volume snapshots
storageClass: "my-storage-class"

recovery:
method: volumeSnapshot
volumeSnapshot:
storageSnapshotName: "example-cluster-daily-backup-20240726021627"
# Note the `-wal` suffix
walSnapshotName: "example-cluster-daily-backup-20240726021627-wal"
6 changes: 6 additions & 0 deletions charts/cluster/templates/_backup.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
backup:
target: "prefer-standby"
retentionPolicy: {{ .Values.backups.retentionPolicy }}
{{- if has .Values.backups.provider (list "s3" "azure" "google") }}
barmanObjectStore:
wal:
compression: {{ .Values.backups.wal.compression }}
Expand All @@ -15,5 +16,10 @@ backup:

{{- $d := dict "chartFullname" (include "cluster.fullname" .) "scope" .Values.backups "secretPrefix" "backup" }}
{{- include "cluster.barmanObjectStoreConfig" $d | nindent 2 }}
{{- else if eq .Values.backups.provider "volumeSnapshot" }}
volumeSnapshot:
online: true
className: {{ .Values.backups.volumeSnapshot.className }}
{{- end }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions charts/cluster/templates/_bootstrap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,19 @@ externalClusters:
name: {{ .Values.recovery.backupName }}
{{- else if eq .Values.recovery.method "object_store" }}
source: objectStoreRecoveryCluster
{{- else if eq .Values.recovery.method "volumeSnapshot" }}
volumeSnapshots:
storage:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: {{ .Values.recovery.volumeSnapshot.storageSnapshotName }}
walStorage:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: {{ .Values.recovery.volumeSnapshot.walSnapshotName }}
{{- end }}

{{- if eq .Values.recovery.method "object_store" }}
externalClusters:
- name: objectStoreRecoveryCluster
barmanObjectStore:
Expand Down
7 changes: 6 additions & 1 deletion charts/cluster/templates/scheduled-backups.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ if .Values.backups.enabled }}
{{ $provider := .Values.backups.provider }}
{{ $context := . -}}
{{ range .Values.backups.scheduledBackups -}}
---
Expand All @@ -10,7 +11,11 @@ metadata:
spec:
immediate: true
schedule: {{ .schedule | quote }}
method: {{ .method }}
{{- if eq $provider "volumeSnapshot" }}
method: volumeSnapshot
{{- else }}
method: barmanObjectStore
{{- end }}
backupOwnerReference: {{ .backupOwnerReference }}
cluster:
name: {{ include "cluster.fullname" $context }}
Expand Down
22 changes: 19 additions & 3 deletions charts/cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@
"backupOwnerReference": {
"type": "string"
},
"method": {
"type": "string"
},
"name": {
"type": "string"
},
Expand All @@ -148,6 +145,14 @@
}
}
},
"volumeSnapshot": {
"type": "object",
"properties": {
"classname": {
"type": "string"
}
}
},
"wal": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -548,6 +553,17 @@
"type": "string"
}
}
},
"volumeSnapshot": {
"type": "object",
"properties": {
"storageSnapshotName": {
"type": "string"
},
"walSnapshotName": {
"type": "string"
}
}
}
}
},
Expand Down
13 changes: 9 additions & 4 deletions charts/cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ recovery:
# * `backup` - Recovers a CNPG cluster from a CNPG backup (PITR supported) Needs to be on the same cluster in the same namespace.
# * `object_store` - Recovers a CNPG cluster from a barman object store (PITR supported).
# * `pg_basebackup` - Recovers a CNPG cluster viaa streaming replication protocol. Useful if you want to
# migrate databases to CloudNativePG, even from outside Kubernetes. # TODO
# migrate databases to CloudNativePG, even from outside Kubernetes.
# * `volumeSnapshot` - Recovers a CNPG cluster from a volume snapshot.
method: backup

## -- Point in time recovery target. Specify one of the following:
Expand Down Expand Up @@ -81,6 +82,10 @@ recovery:
# -- Name of the backup credentials secret
name: ""

volumeSnapshot:
storageSnapshotName: ""
walSnapshotName: ""

# See https://cloudnative-pg.io/documentation/1.22/bootstrap/#bootstrap-from-a-live-cluster-pg_basebackup
pgBaseBackup:
# -- Name of the database used by the application. Default: `app`.
Expand Down Expand Up @@ -267,7 +272,7 @@ backups:
# Azure: https://<storageAccount>.<serviceName>.core.windows.net/<containerName><path>
# Google: gs://<bucket><path>
destinationPath: ""
# -- One of `s3`, `azure` or `google`
# -- One of `s3`, `azure`, `google`, or `volumeSnapshot`
provider: s3
s3:
region: ""
Expand All @@ -289,6 +294,8 @@ backups:
bucket: ""
gkeEnvironment: false
applicationCredentials: ""
volumeSnapshot:
className: ""
secret:
# -- Whether to create a secret for the backup credentials
create: true
Expand Down Expand Up @@ -318,8 +325,6 @@ backups:
schedule: "0 0 0 * * *"
# -- Backup owner reference
backupOwnerReference: self
# -- Backup method, can be `barmanObjectStore` (default) or `volumeSnapshot`
method: barmanObjectStore

# -- Retention policy for backups
retentionPolicy: "30d"
Expand Down