Restore and check your CloudNativePG backup on Kubernetes based on a schedule
⚠️ Warning This project is not tested in production environment and at this stage is only for educational purpose.
- CloudNativePG, cert-manager and barman plugin (with kind you can use the task
setup-kindin theMakefile) - A bucket setup and credentials used to store the backup
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 1
plugins:
- name: barman-cloud.cloudnative-pg.io
isWALArchiver: true
parameters:
barmanObjectName: s3-store
storage:
size: 1Gi
---
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: bucket-cred
stringData:
ACCESS_KEY_ID: EDIT_HERE
SECRET_ACCESS_KEY: EDIT_HERE
---
apiVersion: barmancloud.cnpg.io/v1
kind: ObjectStore
metadata:
name: s3-store
spec:
configuration:
destinationPath: EDIT_HERE
endpointURL: EDIT_HERE
s3Credentials:
accessKeyId:
name: bucket-cred
key: ACCESS_KEY_ID
secretAccessKey:
name: bucket-cred
key: SECRET_ACCESS_KEY
wal:
compression: gzip
maxParallel: 4
data:
compression: gzip
# immediateUpload: true
retentionPolicy: "7d" # keep backups for 7 days
---
# it seems that a full backup is needed to create the base in the s3
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: backup-cluster-example
spec:
cluster:
name: cluster-example
method: plugin
pluginConfiguration:
name: barman-cloud.cloudnative-pg.iomake push IMAGE_TAG=v0.0.1 REPOSITORY=myorg/checkmydump
make deployNOTE
SMTP_USERNAMEandSMTP_PASSWORDare optional, required only if enabled notifications
NOTE SMTP client use ssl
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: checkmydump-test-cred
namespace: checkmydump
stringData:
ACCESS_KEY_ID: EDIT_HERE
SECRET_ACCESS_KEY: EDIT_HERE
SMTP_USERNAME: EDIT_HERE
SMTP_PASSWORD: EDIT_HERENOTE Queries are optional
apiVersion: checkmydump.com/v1alpha1
kind: CheckMyDump
metadata:
name: checkmydump-test
namespace: checkmydump
spec:
schedule: "0 3 * * *"
dbSize: 1G
sourceClusterName: cluster-example
secretName: ...
destinationPath: "..."
endpointURL: "..."
logStore: true
---
apiVersion: checkmydump.com/v1alpha1
kind: CheckMyDumpQuery
metadata:
name: checkmydump-test-query1
namespace: checkmydump
labels:
checkmydumps: checkmydump-test
spec:
query: ...
expectedResult: "..."
---
apiVersion: checkmydump.com/v1alpha1
kind: CheckMyDumpQuery
metadata:
name: checkmydump-test-query2
namespace: checkmydump
labels:
checkmydumps: checkmydump-test
spec:
query: ...