# Backup, migration & restore

In this chapter, you will find general guidance about backing up (and subsequent restoration) of Datalore On-Premises deployment.

## General considerations

There are two places where important data resides:

* PostgreSQL database You can back up and restore data using native database tools (or cloud-native tools, if you are managing a database like [Amazon RDS](https://aws.amazon.com/rds/features/backup/).

* Block storage In both Kubernetes and Docker installation methods, Datalore does not provide any built-in backup and restore mechanism. Instead, you should use underlying infrastructure provider tools to back up the volume used for Datalore.

> **Tip:**
> For example, an [EBS snapshot](https://docs.aws.amazon.com/prescriptive-guidance/latest/backup-recovery/new-ebs-volume-backups.html) could be used if Datalore is deployed on top of AWS, with EBS used as a storage provider.

Procedure: Migration

Sometimes, you might need not to back up but to migrate an existing environment to another (for example, migrating from PoC envs to production, having a different Kubernetes cluster for such cases).

If that's the case, proceed as follows:

1. Export the metadata from the old environment

2. Deploy pods to a new environment

3. Import PersistentVolume/PersistentVolumeClaims metadata

4. Patch PV with the correct UID of the just created PVC

5. Patch PVs to prevent them from being automatically deleted:

```BASH
kubectl patch pv ${PV_NAME} -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
```

6. Save metadata:

```BASH
kubectl get pv/${PV_NAME} --export -o yaml > ${PV_NAME}.yaml; kubectl get pvc/${PVC_NAME} --export -o yaml > ${PVC_NAME}.yaml
```

7. [Deploy a new Datalore installation](install-datalore-on-premises-using-kubernetes-helm.html) to the new cluster; then delete the (new) PVC along with the (new) PV:

```BASH
kubectl delete pvc/${PVC_NAME}
```

8. Kubernetes uses UID to determine the connection between PVC and PV. Therefore, you'll need to create a PV with the metadata from step 3 and patch the PV with the correct UID:

```BASH
kubectl apply -f ${PVC_NAME}.yaml
PVC_UID=$(kubectl get pvc/${PVC_NAME} -o jsonpath='{.metadata.uid}')

kubectl apply -f ${PV_NAME}.yaml
kubectl patch pv ${PV_NAME} -p "{\"spec\":{\"claimRef\":{\"uid\":\"${PVC_UID}\"}}}"
```

9. Stop/remove the old deployment so that you can use this volume in the new cluster.

