Restore from a backup to a new Kubernetes-based environment¶
This page covers restoring a backup to a new cluster on a different Kubernetes cluster or environment. For example, if you migrate to another cloud provider or region. For the other restore paths, see Restore scenarios.
Because PVCs are namespace-specific Kubernetes resources tied to a specific Kubernetes cluster, restoring to a different Kubernetes cluster only works from backups stored in cloud storage, such as S3 or Azure. See Restore limitations.
For Operator version 1.17.0 and earlier
When restoring to a new Kubernetes-based environment, make sure it has a Secrets
object with the same user passwords as in the source cluster. Find more details
about secrets in System Users.
Find the name of the required Secrets object in the
spec.secretsName key in the deploy/cr.yaml. The default Secret name is cluster1-secrets.
This differs for a point-in-time restore — see Restore limitations.
To restore from a backup, you create a PerconaXtraDBClusterRestore object using a restore configuration file. The example of such file is deploy/backup/restore.yaml. You can check available options in the restore options reference.
Before you start¶
- Make sure that the source cluster is running.
-
Find the correct cluster name.
kubectl get pxc -n <namespace> -
Export the cluster name and the namespace where it is running as environment variables. Replace the
cluster1and<namespace>with your values:export CLUSTER=cluster1 export NAMESPACE=<namespace> -
List backups on the source cluster to retrieve the desired backup name. Replace the
<namespace>with your value:kubectl get pxc-backup -n $NAMESPACE -
For point-in-time recovery, disable storing binlogs point-in-time functionality on the existing cluster. You must do it regardless of whether you made the backup with point-in-time recovery or without it. Use the following command and replace the cluster name and the
<namespace>with your values:kubectl patch pxc $CLUSTER \ -n $NAMESPACE \ --type merge \ -p '{"spec":{"backup":{"pitr":{"enabled":false}}}}'
Restore from a full backup¶
To restore from a backup Percona XtraDB Cluster must know where to take the backup from and have access to that storage. See Choose backupName or backupSource for the general rule. A new cluster has no Backup object, so the procedures in this document use backupSource.
You can define the backup storage in two ways: within the restore object configuration or pre-configure it within the target cluster’s Custom Resource manifest.
Approach 1: Define storage configuration in the Restore object¶
If you haven’t defined storage in the target cluster’s cr.yaml file, you can configure it directly in the restore object.
-
Configure the
PerconaXtraDBClusterRestoreCustom Resource. Specify the following keys:-
set
spec.pxcClusterkey to the name of the target cluster to restore the backup on, -
configure the
spec.backupSourcesubsection to point to the cloud storage where the backup is stored.The
spec.backupSourcesubsection should include:- a destination key. Take it from the output of the
kubectl get pxc-backupcommand. The destination consists of thes3://prefix, the S3 bucket name and the backup name. - the necessary storage configuration keys, just like in the
deploy/cr.yamlfile of the source cluster. verifyTLSto verify the storage server TLS certificate- the custom TLS configuration if you use it for backups. Refer to the Configure TLS verification with custom certificates section for more information.
spec: pxcCluster: cluster1 backupSource: verifyTLS: true destination: s3://S3-BUCKET-NAME/BACKUP-NAME s3: bucket: S3-BUCKET-NAME credentialsSecret: my-cluster-name-backup-s3 region: us-west-2 endpointUrl: https://URL-OF-THE-S3-COMPATIBLE-STORAGE caBundle: #If you use custom TLS certificates for S3 storage name: minio-ca-bundle key: ca.crtSpecify the following keys in the
spec.backupSourcesubsection:- The
destinationkey. Take the value from the output of thekubectl get pxc-backupcommand. - The necessary Azure storage configuration keys, just like in the
deploy/cr.yamlfile of the source cluster.
spec: pxcCluster: cluster1 backupSource: destination: azure://AZURE-CONTAINER-NAME/BACKUP-NAME azure: container: AZURE-CONTAINER-NAME credentialsSecret: my-cluster-azure-secret ... - a destination key. Take it from the output of the
-
-
Start the restore process:
kubectl apply -f deploy/backup/restore.yaml -n $NAMESPACE
Approach 2: Storage is configured on the target cluster¶
You can already define the storage where the backup is stored in the backup.storages subsection of your target cluster’s deploy/cr.yaml file. In this case, reference it by name within the restore configuration.
-
Configure the
PerconaXtraDBClusterRestoreCustom Resource. Specify the following keys:-
set
spec.pxcClusterkey to the name of the target cluster to restore the backup on -
specify the storage name in the
backupSource.storageNamekey. The name must match the name in thebackup.storagessubsection of thedeploy/cr.yamlfile -
configure the
spec.backupSourcesubsection with the backup destinationHere are example configurations:
spec: pxcCluster: cluster1 backupSource: destination: s3://S3-BUCKET-NAME/BACKUP-NAME storageName: s3-us-westspec: pxcCluster: cluster1 backupSource: destination: azure://AZURE-CONTAINER-NAME/BACKUP-NAME storageName: azure
-
-
Run the restore process:
kubectl apply -f deploy/backup/restore.yaml -n $NAMESPACE
Verify the restore¶
-
Confirm the Restore object reports
Succeeded:kubectl get pxc-restore -n $NAMESPACE -
Confirm the cluster reports the
readystatus:kubectl get pxc -n $NAMESPACE -
Spot-check the data you expected the backup to contain, then configure the main storage within the target cluster’s
cr.yamlso you can make subsequent backups from the new cluster.
Restore the cluster with point-in-time recovery¶
See Restore with point-in-time recovery. The storage requirements on this page still apply — PITR to a different Kubernetes cluster needs the binlogs in cloud storage, the same as the full backup.
Created: July 4, 2023