Database backup guide¶
This guide provides instructions how to backup and restore database.
Scheduled backups¶
For more details on how to configure backups, you can refer to the scheduled backups documentation for the Percona Operator for MySQL.
You can override the default backup settings by setting the
percona_xtradb_cluster_spec
variable inside your inventory. You can use the
following examples as a starting point.
Persistent volume¶
The following example shows a backup that runs daily at 6 AM to a persistent volume with 3 backups kept. The size of the persistent volume is 50Gi in the example below:
Note
The Percona Operator for MySQL creates a persistent volume claim for every
single backup. This means that if you have 3 backups kept, you will have 3
persistent volume claims. It’s best to set the storage to the size of a
single backup (or perhaps match your backup size to the size of the
cluster storage, which defaults to 160Gi
).
percona_xtradb_cluster_spec:
backup:
image: percona/percona-xtradb-cluster-operator:1.14.0-pxc8.0-backup-pxb8.0.35
storages:
fs-pvc:
type: filesystem
volume:
persistentVolumeClaim:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
schedule:
- name: daily
schedule: 0 6 * * *
keep: 3
storageName: fs-pvc
Amazon S3 or s3-compatible storage¶
To store backups on the Amazon S3, you need to create a Secret with the following values:
apiVersion: v1
kind: Secret
metadata:
name: pxc-backup-s3
type: Opaque
data:
AWS_ACCESS_KEY_ID: # base64-encoded value of access key
AWS_SECRET_ACCESS_KEY: # base64-encoded value of secret access key
kubectl -n openstack apply -f /path/to/secret.yaml
The following example shows a backup that runs daily at 6 AM to an Amazon S3 or S3-compatible storage with 3 backups kept.
percona_xtradb_cluster_spec:
backup:
image: percona/percona-xtradb-cluster-operator:1.14.0-pxc8.0-backup-pxb8.0.35
storages:
s3-bck:
type: s3
s3:
# You can specify the path (sub-folder) to the backups inside the S3 bucket:
# bucket: atmosphere-pxc-backup-1234/region-x
# If prefix is not set, backups are stored in the root directory.
bucket: atmosphere-pxc-backup-1234
region: us-east-1
# If you use some S3-compatible storage instead of the original Amazon S3:
# endpointUrl: https://s3.rgw.ceph.endpoint
# or
# endpointUrl: https://storage.googleapis.com
credentialsSecret: pxc-backup-s3
schedule:
- name: daily
schedule: 0 6 * * *
keep: 3
storageName: s3-bck
On-demand backups¶
To make an on-demand backup, you should first check your Custom Resource
for the necessary options and make changes, if needed. The backup.storages
subsection should contain at least one configured storage.
Examples:
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBClusterBackup
metadata:
finalizers:
# Finalizer can be set even if you use a persistent volume.
- percona.com/delete-backup
name: backup1-pvc
spec:
pxcCluster: percona-xtradb
storageName: fs-pvc
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBClusterBackup
metadata:
finalizers:
- percona.com/delete-backup
name: backup1-s3
spec:
pxcCluster: percona-xtradb
storageName: s3-bck
kubectl -n openstack apply -f /path/to/backup.yaml
Track the backup process by checking the status of the Backup object:
kubectl -n openstack get pxc-backup -w
Restore the cluster from a backup¶
Find the correct backup names. Use the following command to list the available backups:
kubectl -n openstack get pxc-backup
Examples:
Restore with a name from a backup CRD list:
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBClusterRestore
metadata:
name: restore1-from-pvc
spec:
pxcCluster: percona-xtradb
backupName: backup1-pvc
Restore from a remote location without a backup name when the system deletes the backup CRD or when another cluster creates the backup:
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBClusterRestore
metadata:
name: restore1-from-remote-s3
spec:
pxcCluster: percona-xtradb
backupSource:
destination: s3://atmosphere-pxc-backup-1234/region-x/backup1-s3
s3:
credentialsSecret: pxc-backup-s3
region: us-east-1
kubectl -n openstack apply -f /path/to/restore.yaml