# Restore the cluster from a previously saved backup You can restore from a backup as follows: * On the same cluster where you made a backup * On [a new cluster deployed in a different Kubernetes-based environment](backups-restore-to-new-cluster.md). * On a [new cluster with different replica set names](backups-restore-replset-remapping.md) This document focuses on the restore to the same cluster. ## Restore scenarios You can make the following restores: * [Restore to a specific point in time](#make-a-point-in-time-recovery). A precondition for this restore is to [enable saving oplog operations](backups-pitr.md) * [Restore from a backup](#restore-from-a-backup) * [Selective restore from a full logical backup](#selective-restore) For either type of a restore you need to create a Restore object using the [`deploy/backup/restore.yaml` :octicons-link-external-16:](https://github.com/percona/percona-server-mongodb-operator/blob/main/deploy/backup/restore.yaml) manifest. You can specify the backup to restore from in two ways: using the `backupName` or the `backupSource` keys. You must use only one of these options in your restore configuration. Specifying them both together is not allowed. * Use the **`backupName`** option when backup objects exist in the cluster, such as for restoring to the same cluster where the backup was created. When you specify the `backupName`, PBM automatically determines the backup type and performs the corresponding restore procedure. * Use the **`backupSource`** option when there are no backup objects in the cluster, such as [when restoring to a new cluster](backups-restore-to-new-cluster.md). You can also use the `backupSource` for restores to the same cluster, instead of the `backupName`. If you specify the `backupSource`, you must manually specify the backup type (`logical`, `physical` or `incremental`) in the configuration. ## Considerations 1. Check PBM's [considerations :octicons-link-external-16:](https://docs.percona.com/percona-backup-mongodb/usage/restore.html#considerations) to prevent MongoDB clients from accessing the database when the restore is in progress. 2. During the restore, the Operator may delete and recreate Pods. This may cause downtime. The downtime duration depends on the restore type and the database deployment: * *Logical restore in an unsharded cluster* results causes downtime for the duration of the data restore. No Pods are deleted or recreated * *Logical restore in a sharded cluster* causes downtime for the duration of the data restore and the time needed to refresh sharding metadata on `mongos`. This results in deleting and recreating only `mongos` Pods. * *Physical and incremental restore* causes downtime for the entire period required to restore the data and refresh the sharding metadata on `mongos`. The Operator deletes and recreates all Pods - replica set, config server replica set (if present) and mongos Pods. --8<-- [start:backup-prepare] ## Before you begin 1. Make sure that the cluster is running. 2. Export your namespace as an environment variable. Replace the `` placeholder with your value: ```bash export NAMESPACE = ``` 3. Get the backup information. List the backups using this command: ```bash kubectl get psmdb-backup -n $NAMESPACE ``` 4. Get cluster information. List available clusters using this command: ```bash kubectl get psmdb -n $NAMESPACE ``` --8<-- [end:backup-prepare] ## Restore from a backup To restore your Percona Server for MongoDB cluster from any backup, define a `PerconaServerMongoDBRestore` custom resource. The `deploy/backup/restore.yaml` manifest is the same for all restore types. Set the following keys: * set `spec.clusterName` key to the name of the target cluster to restore the backup on, * set `spec.backupName` key to the name of your backup. This is the value from the output of the `kubectl get psmdb-backup` command. During the restore, PBM automatically determines the backup type and performs the corresponding restore procedure. Pass this configuration to the Operator: === "via the YAML manifest" 1. Edit the [deploy/backup/restore.yaml :octicons-link-external-16:](https://github.com/percona/percona-server-mongodb-operator/v{{ release }}/deploy/backup/restore.yaml) file and specify the following keys: ```yaml apiVersion: psmdb.percona.com/v1 kind: PerconaServerMongoDBRestore metadata: name: restore1 spec: clusterName: my-cluster-name backupName: backup1 ``` 2. Start the restore with this command: ```bash kubectl apply -f deploy/backup/restore.yaml -n $NAMESPACE ``` === "via the command line" Instead of storing restore settings in a separate file, you can pass them directly to the `kubectl apply` command as follows: ```bash cat < -n $NAMESPACE -o jsonpath='{.status.latestRestorableTime}' ``` 2. Modify the [deploy/backup/restore.yaml :octicons-link-external-16:](https://github.com/percona/percona-server-mongodb-operator/blob/main/deploy/backup/restore.yaml) manifest and specify the following configuration: * set the `spec.clusterName` key to the name of your cluster. When restoring to the same cluster where the backup was created, the cluster name will be identical in both the Backup and Restore objects. * set the `spec.backupName` key to the name of your backup * configure point-in-time recovery settings in the `pitr` section: * `type` - specify one of the following options * `date` - roll back to a specific date * `latest` - recover to the latest possible transaction * `date` - specify the target datetime in the format `YYYY-MM-DD HH:MM:SS` when `type` is set to `date` Here is the example configuration of the `restore.yaml` file: 3. Pass this configuration to the Operator. === "via the YAML manifest" 1. Edit the [deploy/backup/restore.yaml :octicons-link-external-16:](https://github.com/percona/percona-server-mongodb-operator/v{{release}}/deploy/backup/restore.yaml) file. ```yaml apiVersion: psmdb.percona.com/v1 kind: PerconaServerMongoDBRestore metadata: name: restore1 spec: clusterName: my-cluster-name backupName: backup1 pitr: type: date date: YYYY-MM-DD hh:mm:ss ``` 2. Start the restore with this command: ```bash kubectl apply -f deploy/backup/restore.yaml -n $NAMESPACE ``` === "via the command line" You can skip editing the YAML file and pass its contents to the Operator via the command line. For example: ```bash cat <