# Backup and restore

Keep a copy of the Platforma data that you can restore after a failure or a failed upgrade.

A backup of the database keeps all projects of users safe: after a failure or a failed upgrade, you restore it and continue where you stopped. The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) makes these backups by itself, every day, so you always have earlier copies to go back to. Keep a copy outside the installation too, together with a copy of the secret and the settings that it needs.

## What to keep

The database is the most important part: it holds all projects, and a project refers to its results in the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.). Without the database, the results stay in storage, but no project refers to them.

| Data                                                                                                                                                                                                                                                                                                                                                                                                        | Where it is                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | How to keep it                                                                                                                                                                                       |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Database**: projects, Blocks (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.), users, and the references to all results                                                                                                                                                                                                    | Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.): a volume in the cluster. Single Server mode (The mode in which the Backend and all its jobs run on one Linux machine, the server, with no Kubernetes cluster.): `<main-root>/rocksdb`                                                                                                                                                                                                             | The Backend makes a backup every day: see [Automatic backups of the database](#automatic-backups-of-the-database). Before each upgrade, also make a backup now, and copy it out of the installation. |
| **Results**: the files that analyses make and that users upload                                                                                                                                                                                                                                                                                                                                             | The primary storage: a bucket, or in Single Server mode the folder `<main-root>/primary`                                                                                                                                                                                                                                                                                                                                                                                                                                   | Turn on object versioning or soft delete on the bucket. In Single Server mode, copy the folder.                                                                                                      |
| **Master secret**: encrypts the credentials that the database keeps                                                                                                                                                                                                                                                                                                                                         | Kubernetes: the Secret `platforma-master-secret`. The installers also keep it in AWS Systems Manager Parameter Store or Google Secret Manager. Single Server mode: the master secret file, or the login token that the Backend makes the secret from                                                                                                                                                                                                                                                                       | Keep a copy outside the installation.                                                                                                                                                                |
| **Settings**                                                                                                                                                                                                                                                                                                                                                                                                | AWS installer: the stack parameters. Google Cloud installer: your answers and the release of `platforma-helm`. Terraform modules (The Terraform code that MiLaboratories provides to install Platforma. The cloud-specific Terraform modules make the cluster and its cloud parts in AWS or Google Cloud; the cloud-agnostic Terraform modules install Platforma into the cluster.): your `.tfvars` files and the Terraform state. Helm chart: your values file. Single Server mode: the systemd unit and `/etc/platforma` | Keep them in version control.                                                                                                                                                                        |
| **Workspace (The storage where the Backend and all jobs keep the working files of running jobs. The Backend and the jobs use it at the same time. In Kubernetes, it is a network file system; in Single Server mode, it is a folder on the server.)**: the working files of jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) that run now | Kubernetes: a file system that the Backend and all jobs share. Single Server mode: a folder on the server                                                                                                                                                                                                                                                                                                                                                                                                                  | No backup is necessary: jobs make it again.                                                                                                                                                          |

A database backup is useful only together with the primary storage and the master secret of the same installation.

The files that users import from a data library (A folder or bucket with input data of the company. Users select files from it in the Desktop App. Platforma only reads it.) stay in the library: a project keeps only a link to them. To keep them with the results, copy them into the primary storage: see [Copy the files of a library into the primary storage](/maintain-data-library-access-mode/#copy-the-files-of-a-library-into-the-primary-storage).

## Make a backup now

The Backend makes its [automatic backups](#automatic-backups-of-the-database) on a schedule. Right before each [upgrade](/maintain-upgrading/), make one more backup now, so that it holds the last changes of users.

#### Variant: AWS installer

The commands use the namespace `platforma` and the release `platforma`. Change them if your installation uses other names.

1. **Write the database to a file on your computer.** The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) gives a copy of its database through its debug interface, which listens only inside the pod. The Backend continues to work during the copy.

   ```sh
   kubectl exec deployment/platforma -n platforma -c platforma -- \
     sh -c 'curl -fsS http://127.0.0.1:9091/db/state_raw | gzip' > backup-$(date +%F).tsv.gz
   ```

   When TLS is on in the chart (`network.tls.enabled: true`), the debug interface accepts only HTTPS. Then use `curl -fsSk https://127.0.0.1:9091/db/state_raw` in the command: the certificate names the domain of the installation, not `127.0.0.1`, and the connection does not go out of the pod.

   The time depends on the size of the database: from seconds to hours.

2. **Check the file.** The first test finds a file that stopped too early, for example when the connection to the cluster dropped. The second test finds an empty copy, for example when the debug interface refused the request. The third test finds the error message that the Backend writes as the last line when the copy fails.

   ```sh
   F=backup-$(date +%F).tsv.gz
   gzip -t "$F" && [ -n "$(gzip -dc "$F" | head -c 100)" ] \
     && ! gzip -dc "$F" | tail -1 | grep -q 'Error happened' && echo OK
   ```

   Result: `OK`. Keep the file in a place outside the installation, for example a bucket that Platforma does not use.

3. **Keep a copy of the master secret** if you do not have one outside the cluster.

   ```sh
   kubectl get secret platforma-master-secret -n platforma \
     -o jsonpath='{.data.master-secret}' | base64 -d > master-secret.txt
   ```

   Keep the file as you keep a password, then delete the local copy.

#### Variant: Google Cloud installer

The commands use the namespace `platforma` and the release `platforma`. Change them if your installation uses other names.

1. **Write the database to a file on your computer.** The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) gives a copy of its database through its debug interface, which listens only inside the pod. The Backend continues to work during the copy.

   ```sh
   kubectl exec deployment/platforma -n platforma -c platforma -- \
     sh -c 'curl -fsS http://127.0.0.1:9091/db/state_raw | gzip' > backup-$(date +%F).tsv.gz
   ```

   When TLS is on in the chart (`network.tls.enabled: true`), the debug interface accepts only HTTPS. Then use `curl -fsSk https://127.0.0.1:9091/db/state_raw` in the command: the certificate names the domain of the installation, not `127.0.0.1`, and the connection does not go out of the pod.

   The time depends on the size of the database: from seconds to hours.

2. **Check the file.** The first test finds a file that stopped too early, for example when the connection to the cluster dropped. The second test finds an empty copy, for example when the debug interface refused the request. The third test finds the error message that the Backend writes as the last line when the copy fails.

   ```sh
   F=backup-$(date +%F).tsv.gz
   gzip -t "$F" && [ -n "$(gzip -dc "$F" | head -c 100)" ] \
     && ! gzip -dc "$F" | tail -1 | grep -q 'Error happened' && echo OK
   ```

   Result: `OK`. Keep the file in a place outside the installation, for example a bucket that Platforma does not use.

3. **Keep a copy of the master secret** if you do not have one outside the cluster.

   ```sh
   kubectl get secret platforma-master-secret -n platforma \
     -o jsonpath='{.data.master-secret}' | base64 -d > master-secret.txt
   ```

   Keep the file as you keep a password, then delete the local copy.

#### Variant: Terraform modules

The commands use the namespace `platforma` and the release `platforma`. Change them if your installation uses other names.

1. **Write the database to a file on your computer.** The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) gives a copy of its database through its debug interface, which listens only inside the pod. The Backend continues to work during the copy.

   ```sh
   kubectl exec deployment/platforma -n platforma -c platforma -- \
     sh -c 'curl -fsS http://127.0.0.1:9091/db/state_raw | gzip' > backup-$(date +%F).tsv.gz
   ```

   When TLS is on in the chart (`network.tls.enabled: true`), the debug interface accepts only HTTPS. Then use `curl -fsSk https://127.0.0.1:9091/db/state_raw` in the command: the certificate names the domain of the installation, not `127.0.0.1`, and the connection does not go out of the pod.

   The time depends on the size of the database: from seconds to hours.

2. **Check the file.** The first test finds a file that stopped too early, for example when the connection to the cluster dropped. The second test finds an empty copy, for example when the debug interface refused the request. The third test finds the error message that the Backend writes as the last line when the copy fails.

   ```sh
   F=backup-$(date +%F).tsv.gz
   gzip -t "$F" && [ -n "$(gzip -dc "$F" | head -c 100)" ] \
     && ! gzip -dc "$F" | tail -1 | grep -q 'Error happened' && echo OK
   ```

   Result: `OK`. Keep the file in a place outside the installation, for example a bucket that Platforma does not use.

3. **Keep a copy of the master secret** if you do not have one outside the cluster.

   ```sh
   kubectl get secret platforma-master-secret -n platforma \
     -o jsonpath='{.data.master-secret}' | base64 -d > master-secret.txt
   ```

   Keep the file as you keep a password, then delete the local copy.

#### Variant: Helm chart

The commands use the namespace `platforma` and the release `platforma`. Change them if your installation uses other names.

1. **Write the database to a file on your computer.** The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) gives a copy of its database through its debug interface, which listens only inside the pod. The Backend continues to work during the copy.

   ```sh
   kubectl exec deployment/platforma -n platforma -c platforma -- \
     sh -c 'curl -fsS http://127.0.0.1:9091/db/state_raw | gzip' > backup-$(date +%F).tsv.gz
   ```

   When TLS is on in the chart (`network.tls.enabled: true`), the debug interface accepts only HTTPS. Then use `curl -fsSk https://127.0.0.1:9091/db/state_raw` in the command: the certificate names the domain of the installation, not `127.0.0.1`, and the connection does not go out of the pod.

   The time depends on the size of the database: from seconds to hours.

2. **Check the file.** The first test finds a file that stopped too early, for example when the connection to the cluster dropped. The second test finds an empty copy, for example when the debug interface refused the request. The third test finds the error message that the Backend writes as the last line when the copy fails.

   ```sh
   F=backup-$(date +%F).tsv.gz
   gzip -t "$F" && [ -n "$(gzip -dc "$F" | head -c 100)" ] \
     && ! gzip -dc "$F" | tail -1 | grep -q 'Error happened' && echo OK
   ```

   Result: `OK`. Keep the file in a place outside the installation, for example a bucket that Platforma does not use.

3. **Keep a copy of the master secret** if you do not have one outside the cluster.

   ```sh
   kubectl get secret platforma-master-secret -n platforma \
     -o jsonpath='{.data.master-secret}' | base64 -d > master-secret.txt
   ```

   Keep the file as you keep a password, then delete the local copy.

#### Variant: Single Server

In Single Server mode, copy the full data folder while the Backend is stopped.

1. **Stop the Backend:** `sudo systemctl stop platforma`.

2. **Check that the Backend stopped.**

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) stopped:

   ```sh
   systemctl is-active platforma
   pgrep -fa /opt/platforma/binaries/platforma
   ```

   Result: the first command prints `inactive`, and the second command prints nothing. If a process is still there, wait and run the commands again. Do not continue while the process exists: it can still write to the database.

3. **Make the archive.**

   ```sh
   sudo tar -czf platforma-backup-$(date +%F).tar.gz /data/platforma /etc/platforma
   ```

4. **Start the Backend:** `sudo systemctl start platforma`.

The archive holds the database, the results and the settings. Move it to a different machine.

> **The results make the archive large:**
>
> By default, the primary storage is the folder `/data/platforma/primary`, inside the data folder. So the archive also holds all results and uploaded files, and can take hours for a large installation. The Backend stays stopped during this time, and users cannot work.
>
> To make the stop shorter, archive the data folder without the results, and copy the results separately while the Backend runs. The files in the primary storage never change after the Backend writes them, so each new copy adds only the new files:
>
> ```sh
> sudo tar -czf platforma-backup-$(date +%F).tar.gz --exclude=/data/platforma/primary \
>   /data/platforma /etc/platforma
> ```
>
> Use this command in step 3, after the check of step 2. Then start the Backend and copy the results:
>
> ```sh
> sudo rsync -a /data/platforma/primary/ <backup-place>/primary/
> ```
>
> Copy the results after the archive, not before: then the copy has every file that the database in the archive refers to.

**Only the database, without a stop.** The archive needs a stop of the Backend. To keep the last changes of users before an upgrade without a stop, write only the database to a file while the Backend runs:

1. **Write the database to a file.**

   The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) gives a copy of its database through its debug API. In Single Server mode (The mode in which the Backend and all its jobs run on one Linux machine, the server, with no Kubernetes cluster.), the debug API is off by default. To turn it on, add a line to the environment file of the service and restart the Backend. You do this one time:

   ```sh
   echo 'PL_DEBUG_ENABLED=true' | sudo tee -a /etc/platforma/platforma.env > /dev/null
   sudo systemctl restart platforma
   ```

   The option `--debug-enabled` in the start command does the same. The debug API then listens on `127.0.0.1:9091` (the options `--debug-ip` and `--debug-port`), so run the next command on the server. The Backend continues to work during the copy.

   ```sh
   curl -fsS http://127.0.0.1:9091/db/state_raw | gzip > backup-$(date +%F).tsv.gz
   ```

   When the Backend uses TLS (`--listen-tls` or `--self-signed-tls`), the debug API accepts only HTTPS. Then use `curl -fsSk https://127.0.0.1:9091/db/state_raw` in the command: the certificate names the domain of the server, not `127.0.0.1`, and the connection does not go out of the server.

   > **The debug API does not ask for a sign-in:**
   >
   > Each person or program that can connect to the debug API can read the full database. Keep it on a local address: do not set `--debug-ip` to an address that other hosts can reach.

2. **Check the file.** The first test finds a file that stopped too early. The second test finds the error message that the Backend writes as the last line when the copy fails.

   ```sh
   F=backup-$(date +%F).tsv.gz
   gzip -t "$F" && ! gzip -dc "$F" | tail -1 | grep -q 'Error happened' && echo OK
   ```

   Result: `OK`. Move the file to a different machine.

The file holds only the database. Keep the results and the settings as [What to keep](#what-to-keep) says. To restore the file, see [Put back the database](#put-back-the-database), “From a backup file”.

## Disk snapshots

On Kubernetes, the database is on one cloud disk: the volume `platforma-database`. A snapshot of this disk is a fast copy that the cloud keeps for you. Each new snapshot keeps only the data that changed, so you can make one every day at a low cost, and a restore takes minutes. A snapshot works only in the same cloud project or account. For a copy that you can restore anywhere, also make the backup of [Make a backup now](#make-a-backup-now).

A snapshot holds only the database. Protect the primary storage separately: the installers do not turn on object versioning on the bucket, so turn it on, or soft delete on Google Cloud Storage.

#### Variant: AWS installer

The database disk is a gp3 EBS volume (StorageClass `gp3-retain`, driver `ebs.csi.aws.com`). The installer does not install the snapshot parts of Kubernetes. Before the first snapshot:

1. Add the Amazon EKS add-on `snapshot-controller` to the cluster. It also adds the Kubernetes objects for snapshots.

   ```sh
   aws eks create-addon --cluster-name <cluster-name> --addon-name snapshot-controller
   ```

2. Create a VolumeSnapshotClass:

   ```yaml
   apiVersion: snapshot.storage.k8s.io/v1
   kind: VolumeSnapshotClass
   metadata:
     name: platforma-database
   driver: ebs.csi.aws.com
   deletionPolicy: Retain
   ```

To make snapshots on a schedule without Kubernetes, use AWS Backup or Amazon Data Lifecycle Manager on the EBS volume. The cloud makes such a snapshot while the Backend runs. It is crash-consistent: the database is as after a sudden power failure, and the Backend usually starts on it. Use it as a second copy, not as your only backup. The ID of the volume is in its PersistentVolume:

```sh
kubectl get pv $(kubectl get pvc platforma-database -n platforma -o jsonpath='{.spec.volumeName}') \
  -o jsonpath='{.spec.csi.volumeHandle}{"\n"}'
```

`deletionPolicy: Retain` keeps the snapshot in the cloud when somebody deletes its Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) object, for example with the namespace.

**Make a snapshot.** Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) for the snapshot, so that the disk does not change during the copy.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Make the snapshot,** and wait until it is ready:

   ```sh
   cat <<'EOF' | kubectl apply -f -
   apiVersion: snapshot.storage.k8s.io/v1
   kind: VolumeSnapshot
   metadata:
     name: platforma-database-2026-11-24
     namespace: platforma
   spec:
     volumeSnapshotClassName: platforma-database
     source:
       persistentVolumeClaimName: platforma-database
   EOF


   kubectl wait volumesnapshot/platforma-database-2026-11-24 -n platforma \
     --for=jsonpath='{.status.readyToUse}'=true --timeout=60m
   ```

   Use the date in the name of each snapshot. The first snapshot copies the full disk and takes the longest.

3. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

**Restore from a snapshot.** The restore makes a new database disk from the snapshot.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Check the snapshot.** Do not continue unless the result is `true`:

   ```sh
   kubectl get volumesnapshot platforma-database-2026-11-24 -n platforma \
     -o jsonpath='{.status.readyToUse}{"\n"}'
   ```

3. **Keep the old disk, and write down its settings.** The StorageClasses of the installers have `reclaimPolicy: Delete`: without this step, the deletion of the volume claim deletes the disk.

   ```sh
   PV=$(kubectl get pvc platforma-database -n platforma -o jsonpath='{.spec.volumeName}')
   kubectl patch pv "$PV" -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
   kubectl get pvc platforma-database -n platforma \
     -o jsonpath='{.spec.storageClassName} {.spec.resources.requests.storage}{"\n"}'
   ```

   Result: the StorageClass and the size of the volume, for example `gp3 50Gi`.

4. **Make a new database volume from the snapshot.** Use the StorageClass and the size of step 3. The labels and annotations let Helm keep managing the new volume.

   ```sh
   kubectl delete pvc platforma-database -n platforma


   cat <<'EOF' | kubectl apply -f -
   apiVersion: v1
   kind: PersistentVolumeClaim
   metadata:
     name: platforma-database
     namespace: platforma
     labels:
       app.kubernetes.io/managed-by: Helm
       app.kubernetes.io/component: database
     annotations:
       meta.helm.sh/release-name: platforma
       meta.helm.sh/release-namespace: platforma
       helm.sh/resource-policy: keep
   spec:
     accessModes: [ReadWriteOnce]
     storageClassName: <storage-class>
     resources:
       requests:
         storage: <size>
     dataSource:
       apiGroup: snapshot.storage.k8s.io
       kind: VolumeSnapshot
       name: platforma-database-2026-11-24
   EOF
   ```

5. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results. Then delete the old disk: `kubectl delete pv "$PV"`, and delete the disk in the console of the cloud account of your company.

#### Variant: Google Cloud installer

The database disk is an SSD Persistent Disk (StorageClass `platforma-database-retain`, driver `pd.csi.storage.gke.io`). The installer turns on the Persistent Disk CSI driver, and GKE has the snapshot parts of Kubernetes. Before the first snapshot, only create a VolumeSnapshotClass:

```yaml
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
  name: platforma-database
driver: pd.csi.storage.gke.io
deletionPolicy: Retain
```

To make snapshots on a schedule without Kubernetes, attach a snapshot schedule to the disk in Compute Engine. The cloud makes such a snapshot while the Backend runs. It is crash-consistent: the database is as after a sudden power failure, and the Backend usually starts on it. Use it as a second copy, not as your only backup. The name of the disk is in its PersistentVolume:

```sh
kubectl get pv $(kubectl get pvc platforma-database -n platforma -o jsonpath='{.spec.volumeName}') \
  -o jsonpath='{.spec.csi.volumeHandle}{"\n"}'
```

`deletionPolicy: Retain` keeps the snapshot in the cloud when somebody deletes its Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) object, for example with the namespace.

**Make a snapshot.** Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) for the snapshot, so that the disk does not change during the copy.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Make the snapshot,** and wait until it is ready:

   ```sh
   cat <<'EOF' | kubectl apply -f -
   apiVersion: snapshot.storage.k8s.io/v1
   kind: VolumeSnapshot
   metadata:
     name: platforma-database-2026-11-24
     namespace: platforma
   spec:
     volumeSnapshotClassName: platforma-database
     source:
       persistentVolumeClaimName: platforma-database
   EOF


   kubectl wait volumesnapshot/platforma-database-2026-11-24 -n platforma \
     --for=jsonpath='{.status.readyToUse}'=true --timeout=60m
   ```

   Use the date in the name of each snapshot. The first snapshot copies the full disk and takes the longest.

3. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

**Restore from a snapshot.** The restore makes a new database disk from the snapshot.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Check the snapshot.** Do not continue unless the result is `true`:

   ```sh
   kubectl get volumesnapshot platforma-database-2026-11-24 -n platforma \
     -o jsonpath='{.status.readyToUse}{"\n"}'
   ```

3. **Keep the old disk, and write down its settings.** The StorageClasses of the installers have `reclaimPolicy: Delete`: without this step, the deletion of the volume claim deletes the disk.

   ```sh
   PV=$(kubectl get pvc platforma-database -n platforma -o jsonpath='{.spec.volumeName}')
   kubectl patch pv "$PV" -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
   kubectl get pvc platforma-database -n platforma \
     -o jsonpath='{.spec.storageClassName} {.spec.resources.requests.storage}{"\n"}'
   ```

   Result: the StorageClass and the size of the volume, for example `gp3 50Gi`.

4. **Make a new database volume from the snapshot.** Use the StorageClass and the size of step 3. The labels and annotations let Helm keep managing the new volume.

   ```sh
   kubectl delete pvc platforma-database -n platforma


   cat <<'EOF' | kubectl apply -f -
   apiVersion: v1
   kind: PersistentVolumeClaim
   metadata:
     name: platforma-database
     namespace: platforma
     labels:
       app.kubernetes.io/managed-by: Helm
       app.kubernetes.io/component: database
     annotations:
       meta.helm.sh/release-name: platforma
       meta.helm.sh/release-namespace: platforma
       helm.sh/resource-policy: keep
   spec:
     accessModes: [ReadWriteOnce]
     storageClassName: <storage-class>
     resources:
       requests:
         storage: <size>
     dataSource:
       apiGroup: snapshot.storage.k8s.io
       kind: VolumeSnapshot
       name: platforma-database-2026-11-24
   EOF
   ```

5. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results. Then delete the old disk: `kubectl delete pv "$PV"`, and delete the disk in the console of the cloud account of your company.

#### Variant: Terraform modules

With the cloud-specific Terraform modules (The Terraform modules platforma-tf-cloud-base and platforma-tf-cloud-cluster. There is one pair for each cloud, AWS and Google Cloud. The roots cloud and cluster apply them. They make the network, the Kubernetes cluster, the storage, the cloud identities and the registry caches. They give the hand-off file cluster_config to the cloud-agnostic Terraform modules.), the database disk has the StorageClass `platforma-database` that `platforma-tf-cloud-cluster` makes: an EBS volume on AWS (driver `ebs.csi.aws.com`), a Persistent Disk on Google Cloud (driver `pd.csi.storage.gke.io`). The modules do not install the snapshot parts of Kubernetes. Before the first snapshot:

1. On AWS only, add the Amazon EKS add-on `snapshot-controller` to the cluster. GKE has these parts.

   ```sh
   aws eks create-addon --cluster-name <cluster-name> --addon-name snapshot-controller
   ```

2. Create a VolumeSnapshotClass for the driver of the disk:

   ```yaml
   apiVersion: snapshot.storage.k8s.io/v1
   kind: VolumeSnapshotClass
   metadata:
     name: platforma-database
   driver: ebs.csi.aws.com          # Google Cloud: pd.csi.storage.gke.io
   deletionPolicy: Retain
   ```

On an own cluster, do as in the tab “Helm chart”.

`deletionPolicy: Retain` keeps the snapshot in the cloud when somebody deletes its Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) object, for example with the namespace.

**Make a snapshot.** Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) for the snapshot, so that the disk does not change during the copy.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Make the snapshot,** and wait until it is ready:

   ```sh
   cat <<'EOF' | kubectl apply -f -
   apiVersion: snapshot.storage.k8s.io/v1
   kind: VolumeSnapshot
   metadata:
     name: platforma-database-2026-11-24
     namespace: platforma
   spec:
     volumeSnapshotClassName: platforma-database
     source:
       persistentVolumeClaimName: platforma-database
   EOF


   kubectl wait volumesnapshot/platforma-database-2026-11-24 -n platforma \
     --for=jsonpath='{.status.readyToUse}'=true --timeout=60m
   ```

   Use the date in the name of each snapshot. The first snapshot copies the full disk and takes the longest.

3. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

**Restore from a snapshot.** The restore makes a new database disk from the snapshot.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Check the snapshot.** Do not continue unless the result is `true`:

   ```sh
   kubectl get volumesnapshot platforma-database-2026-11-24 -n platforma \
     -o jsonpath='{.status.readyToUse}{"\n"}'
   ```

3. **Keep the old disk, and write down its settings.** The StorageClasses of the installers have `reclaimPolicy: Delete`: without this step, the deletion of the volume claim deletes the disk.

   ```sh
   PV=$(kubectl get pvc platforma-database -n platforma -o jsonpath='{.spec.volumeName}')
   kubectl patch pv "$PV" -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
   kubectl get pvc platforma-database -n platforma \
     -o jsonpath='{.spec.storageClassName} {.spec.resources.requests.storage}{"\n"}'
   ```

   Result: the StorageClass and the size of the volume, for example `gp3 50Gi`.

4. **Make a new database volume from the snapshot.** Use the StorageClass and the size of step 3. The labels and annotations let Helm keep managing the new volume.

   ```sh
   kubectl delete pvc platforma-database -n platforma


   cat <<'EOF' | kubectl apply -f -
   apiVersion: v1
   kind: PersistentVolumeClaim
   metadata:
     name: platforma-database
     namespace: platforma
     labels:
       app.kubernetes.io/managed-by: Helm
       app.kubernetes.io/component: database
     annotations:
       meta.helm.sh/release-name: platforma
       meta.helm.sh/release-namespace: platforma
       helm.sh/resource-policy: keep
   spec:
     accessModes: [ReadWriteOnce]
     storageClassName: <storage-class>
     resources:
       requests:
         storage: <size>
     dataSource:
       apiGroup: snapshot.storage.k8s.io
       kind: VolumeSnapshot
       name: platforma-database-2026-11-24
   EOF
   ```

5. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results. Then delete the old disk: `kubectl delete pv "$PV"`, and delete the disk in the console of the cloud account of your company.

#### Variant: Helm chart

Snapshots depend on the cluster. Before the first snapshot:

1. Make sure that the cluster has a CSI driver for the database disk that can make snapshots, and the Kubernetes snapshot controller. Ask the team that runs the cluster.

2. Create a VolumeSnapshotClass with the name `platforma-database` for the driver of your StorageClass:

   ```yaml
   apiVersion: snapshot.storage.k8s.io/v1
   kind: VolumeSnapshotClass
   metadata:
     name: platforma-database
   driver: <the driver of your StorageClass>
   deletionPolicy: Retain
   ```

`deletionPolicy: Retain` keeps the snapshot in the cloud when somebody deletes its Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) object, for example with the namespace.

**Make a snapshot.** Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) for the snapshot, so that the disk does not change during the copy.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Make the snapshot,** and wait until it is ready:

   ```sh
   cat <<'EOF' | kubectl apply -f -
   apiVersion: snapshot.storage.k8s.io/v1
   kind: VolumeSnapshot
   metadata:
     name: platforma-database-2026-11-24
     namespace: platforma
   spec:
     volumeSnapshotClassName: platforma-database
     source:
       persistentVolumeClaimName: platforma-database
   EOF


   kubectl wait volumesnapshot/platforma-database-2026-11-24 -n platforma \
     --for=jsonpath='{.status.readyToUse}'=true --timeout=60m
   ```

   Use the date in the name of each snapshot. The first snapshot copies the full disk and takes the longest.

3. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

**Restore from a snapshot.** The restore makes a new database disk from the snapshot.

1. **Stop the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Check the snapshot.** Do not continue unless the result is `true`:

   ```sh
   kubectl get volumesnapshot platforma-database-2026-11-24 -n platforma \
     -o jsonpath='{.status.readyToUse}{"\n"}'
   ```

3. **Keep the old disk, and write down its settings.** The StorageClasses of the installers have `reclaimPolicy: Delete`: without this step, the deletion of the volume claim deletes the disk.

   ```sh
   PV=$(kubectl get pvc platforma-database -n platforma -o jsonpath='{.spec.volumeName}')
   kubectl patch pv "$PV" -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
   kubectl get pvc platforma-database -n platforma \
     -o jsonpath='{.spec.storageClassName} {.spec.resources.requests.storage}{"\n"}'
   ```

   Result: the StorageClass and the size of the volume, for example `gp3 50Gi`.

4. **Make a new database volume from the snapshot.** Use the StorageClass and the size of step 3. The labels and annotations let Helm keep managing the new volume.

   ```sh
   kubectl delete pvc platforma-database -n platforma


   cat <<'EOF' | kubectl apply -f -
   apiVersion: v1
   kind: PersistentVolumeClaim
   metadata:
     name: platforma-database
     namespace: platforma
     labels:
       app.kubernetes.io/managed-by: Helm
       app.kubernetes.io/component: database
     annotations:
       meta.helm.sh/release-name: platforma
       meta.helm.sh/release-namespace: platforma
       helm.sh/resource-policy: keep
   spec:
     accessModes: [ReadWriteOnce]
     storageClassName: <storage-class>
     resources:
       requests:
         storage: <size>
     dataSource:
       apiGroup: snapshot.storage.k8s.io
       kind: VolumeSnapshot
       name: platforma-database-2026-11-24
   EOF
   ```

5. **Start the Backend.**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results. Then delete the old disk: `kubectl delete pv "$PV"`, and delete the disk in the console of the cloud account of your company.

#### Variant: Single Server

Use the snapshots of the server’s disk, if your platform has them. Stop the Backend before the snapshot, and check that it stopped, as in [Make a backup now](#make-a-backup-now).

## Restore

A restore replaces the database with the backup. All changes that users made after the backup are lost. Results made after the backup stay in the storage, but no project refers to them.

> **Caution:**
>
> Restore with the same Backend version that made the backup, or a later one. An earlier version does not start on the database of a later version: it stops with an error, for example `attempt to run service on top of DB generated by newer Platforma Backend version`.

### Automatic backups of the database

After an outage, a damaged database or any other failure, you can always go back to an earlier copy of the database: the Backend keeps them in the primary storage.

- **When:** the Backend makes a backup when it starts, and then every 24 hours while it runs.
- **Where:** in the folder `db-backups/` of the primary storage: the bucket and its prefix, or in Single Server mode the folder `/data/platforma/primary/db-backups/`.
- **Names:** the date and time of the backup in UTC, for example `2026-11-27_031500.tsv.gz`. The names sort from the oldest to the newest.
- **How many:** the newest 14. After each new backup, the Backend deletes the older ones.
- **Checks:** before the upload, the Backend compares the backup with the database.

The same holds in Kubernetes and in Single Server mode. To change the interval, the number of kept backups, the folder, or to send the backups to a different bucket or folder, see [Backups of the database](/configuration-storage/#backups-of-the-database). The automatic backups are as safe as the primary storage: protect it, as [What to keep](#what-to-keep) says, or send the backups to a different place.

### Get the backup file

Choose the newest backup from before the failure. The commands use the bucket and the prefix of the primary storage; if the backups go to a different place, use that place.

#### Variant: Kubernetes cluster

List the backups, then copy the chosen file to your computer.

*AWS S3 bucket*

```sh
aws s3 ls s3://<bucket>/<prefix>db-backups/
aws s3 cp s3://<bucket>/<prefix>db-backups/<name>.tsv.gz .
```

*GCS bucket*

```sh
gcloud storage ls gs://<bucket>/<prefix>db-backups/
gcloud storage cp gs://<bucket>/<prefix>db-backups/<name>.tsv.gz .
```

Result: the file is on your computer. It is the `<backup-file>` of the restore steps.

#### Variant: Single Server

List the backups, then copy the chosen file to a folder that the user `platforma` can read:

```sh
ls /data/platforma/primary/db-backups/
sudo cp /data/platforma/primary/db-backups/<name>.tsv.gz /tmp/
```

If the primary storage is a bucket, copy the file from the bucket, as in the tab “Kubernetes cluster”.

Result: the file is in `/tmp`. It is the `<backup-file>` of the restore steps.

### Put back the database

#### Variant: AWS installer

1. **Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.).**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Start a restore pod.** The pod copies the settings of the Backend: the same nodes, resources and database volume. Set `IMAGE` to the Backend image that must run after the restore. After a failed upgrade, this is the old image. The command makes the pod with [`jq`](https://jqlang.org/download/): install it on your computer first.

   ```sh
   IMAGE=<backend-image>


   kubectl get deployment platforma -n platforma -o json | jq --arg image "$IMAGE" '
     .spec.template.spec as $s
     | ($s.containers[] | select(.name == "platforma")) as $c
     | {
         apiVersion: "v1", kind: "Pod",
         metadata: {name: "platforma-restore", namespace: .metadata.namespace},
         spec: {
           restartPolicy: "Never",
           securityContext: $s.securityContext,
           nodeSelector: $s.nodeSelector,
           tolerations: $s.tolerations,
           affinity: $s.affinity,
           containers: [{
             name: "restore",
             image: $image,
             command: ["sleep", "infinity"],
             securityContext: $c.securityContext,
             resources: $c.resources,
             volumeMounts: [{name: "database", mountPath: "/data/database"}]
           }],
           volumes: [$s.volumes[] | select(.name == "database")]
         }
       }' | kubectl apply -f -


   kubectl wait pod/platforma-restore -n platforma --for=condition=Ready --timeout=600s
   ```

3. **Restore the backup.** Copy the file into the pod, and empty the database folder: a newer version can write files that the restore of an older version cannot open. Then start the restore in the background, so that it continues if your connection stops:

   ```sh
   kubectl exec -i platforma-restore -n platforma -- \
     sh -c 'cat > /tmp/backup.tsv.gz' < <backup-file>


   kubectl exec platforma-restore -n platforma -- \
     find /data/database -mindepth 1 -maxdepth 1 ! -name lost+found -exec rm -rf {} +


   kubectl exec platforma-restore -n platforma -- sh -c \
     'nohup sh -c "/app/platforma --restore-db=/tmp/backup.tsv.gz --db-dir=/data/database --force && echo RESTORE OK || echo RESTORE FAILED" > /tmp/restore.log 2>&1 &'
   ```

   The restore takes from minutes to hours: this depends on the size of the database. To see the progress:

   ```sh
   kubectl exec platforma-restore -n platforma -- tail -5 /tmp/restore.log
   ```

   Result: the last line is `RESTORE OK`. Then delete the pod: `kubectl delete pod platforma-restore -n platforma`. If the last line is `RESTORE FAILED`, keep the pod and send `/tmp/restore.log` to MiLaboratories support.

4. **Start the Backend.** After a failed upgrade, deploy the old version: see [Go back to the old version](/maintain-upgrading/#go-back-to-the-old-version). In all other cases:

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results.

#### Variant: Google Cloud installer

1. **Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.).**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Start a restore pod.** The pod copies the settings of the Backend: the same nodes, resources and database volume. Set `IMAGE` to the Backend image that must run after the restore. After a failed upgrade, this is the old image. The command makes the pod with [`jq`](https://jqlang.org/download/): install it on your computer first.

   ```sh
   IMAGE=<backend-image>


   kubectl get deployment platforma -n platforma -o json | jq --arg image "$IMAGE" '
     .spec.template.spec as $s
     | ($s.containers[] | select(.name == "platforma")) as $c
     | {
         apiVersion: "v1", kind: "Pod",
         metadata: {name: "platforma-restore", namespace: .metadata.namespace},
         spec: {
           restartPolicy: "Never",
           securityContext: $s.securityContext,
           nodeSelector: $s.nodeSelector,
           tolerations: $s.tolerations,
           affinity: $s.affinity,
           containers: [{
             name: "restore",
             image: $image,
             command: ["sleep", "infinity"],
             securityContext: $c.securityContext,
             resources: $c.resources,
             volumeMounts: [{name: "database", mountPath: "/data/database"}]
           }],
           volumes: [$s.volumes[] | select(.name == "database")]
         }
       }' | kubectl apply -f -


   kubectl wait pod/platforma-restore -n platforma --for=condition=Ready --timeout=600s
   ```

3. **Restore the backup.** Copy the file into the pod, and empty the database folder: a newer version can write files that the restore of an older version cannot open. Then start the restore in the background, so that it continues if your connection stops:

   ```sh
   kubectl exec -i platforma-restore -n platforma -- \
     sh -c 'cat > /tmp/backup.tsv.gz' < <backup-file>


   kubectl exec platforma-restore -n platforma -- \
     find /data/database -mindepth 1 -maxdepth 1 ! -name lost+found -exec rm -rf {} +


   kubectl exec platforma-restore -n platforma -- sh -c \
     'nohup sh -c "/app/platforma --restore-db=/tmp/backup.tsv.gz --db-dir=/data/database --force && echo RESTORE OK || echo RESTORE FAILED" > /tmp/restore.log 2>&1 &'
   ```

   The restore takes from minutes to hours: this depends on the size of the database. To see the progress:

   ```sh
   kubectl exec platforma-restore -n platforma -- tail -5 /tmp/restore.log
   ```

   Result: the last line is `RESTORE OK`. Then delete the pod: `kubectl delete pod platforma-restore -n platforma`. If the last line is `RESTORE FAILED`, keep the pod and send `/tmp/restore.log` to MiLaboratories support.

4. **Start the Backend.** After a failed upgrade, deploy the old version: see [Go back to the old version](/maintain-upgrading/#go-back-to-the-old-version). In all other cases:

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results.

#### Variant: Terraform modules

1. **Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.).**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Start a restore pod.** The pod copies the settings of the Backend: the same nodes, resources and database volume. Set `IMAGE` to the Backend image that must run after the restore. After a failed upgrade, this is the old image. The command makes the pod with [`jq`](https://jqlang.org/download/): install it on your computer first.

   ```sh
   IMAGE=<backend-image>


   kubectl get deployment platforma -n platforma -o json | jq --arg image "$IMAGE" '
     .spec.template.spec as $s
     | ($s.containers[] | select(.name == "platforma")) as $c
     | {
         apiVersion: "v1", kind: "Pod",
         metadata: {name: "platforma-restore", namespace: .metadata.namespace},
         spec: {
           restartPolicy: "Never",
           securityContext: $s.securityContext,
           nodeSelector: $s.nodeSelector,
           tolerations: $s.tolerations,
           affinity: $s.affinity,
           containers: [{
             name: "restore",
             image: $image,
             command: ["sleep", "infinity"],
             securityContext: $c.securityContext,
             resources: $c.resources,
             volumeMounts: [{name: "database", mountPath: "/data/database"}]
           }],
           volumes: [$s.volumes[] | select(.name == "database")]
         }
       }' | kubectl apply -f -


   kubectl wait pod/platforma-restore -n platforma --for=condition=Ready --timeout=600s
   ```

3. **Restore the backup.** Copy the file into the pod, and empty the database folder: a newer version can write files that the restore of an older version cannot open. Then start the restore in the background, so that it continues if your connection stops:

   ```sh
   kubectl exec -i platforma-restore -n platforma -- \
     sh -c 'cat > /tmp/backup.tsv.gz' < <backup-file>


   kubectl exec platforma-restore -n platforma -- \
     find /data/database -mindepth 1 -maxdepth 1 ! -name lost+found -exec rm -rf {} +


   kubectl exec platforma-restore -n platforma -- sh -c \
     'nohup sh -c "/app/platforma --restore-db=/tmp/backup.tsv.gz --db-dir=/data/database --force && echo RESTORE OK || echo RESTORE FAILED" > /tmp/restore.log 2>&1 &'
   ```

   The restore takes from minutes to hours: this depends on the size of the database. To see the progress:

   ```sh
   kubectl exec platforma-restore -n platforma -- tail -5 /tmp/restore.log
   ```

   Result: the last line is `RESTORE OK`. Then delete the pod: `kubectl delete pod platforma-restore -n platforma`. If the last line is `RESTORE FAILED`, keep the pod and send `/tmp/restore.log` to MiLaboratories support.

4. **Start the Backend.** After a failed upgrade, deploy the old version: see [Go back to the old version](/maintain-upgrading/#go-back-to-the-old-version). In all other cases:

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results.

#### Variant: Helm chart

1. **Stop the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.).**

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=0
   ```

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) pod is gone. The filter leaves out the pods of the cleanup job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.), which have the same release label:

   ```sh
   kubectl get pods -n platforma -l 'app.kubernetes.io/instance=platforma,!app.kubernetes.io/component'
   ```

   Result: `No resources found in platforma namespace.` If the list shows a pod, also in the state `Terminating`, wait and run the command again. Do not continue while the pod exists: it can still write to the database.

2. **Start a restore pod.** The pod copies the settings of the Backend: the same nodes, resources and database volume. Set `IMAGE` to the Backend image that must run after the restore. After a failed upgrade, this is the old image. The command makes the pod with [`jq`](https://jqlang.org/download/): install it on your computer first.

   ```sh
   IMAGE=<backend-image>


   kubectl get deployment platforma -n platforma -o json | jq --arg image "$IMAGE" '
     .spec.template.spec as $s
     | ($s.containers[] | select(.name == "platforma")) as $c
     | {
         apiVersion: "v1", kind: "Pod",
         metadata: {name: "platforma-restore", namespace: .metadata.namespace},
         spec: {
           restartPolicy: "Never",
           securityContext: $s.securityContext,
           nodeSelector: $s.nodeSelector,
           tolerations: $s.tolerations,
           affinity: $s.affinity,
           containers: [{
             name: "restore",
             image: $image,
             command: ["sleep", "infinity"],
             securityContext: $c.securityContext,
             resources: $c.resources,
             volumeMounts: [{name: "database", mountPath: "/data/database"}]
           }],
           volumes: [$s.volumes[] | select(.name == "database")]
         }
       }' | kubectl apply -f -


   kubectl wait pod/platforma-restore -n platforma --for=condition=Ready --timeout=600s
   ```

3. **Restore the backup.** Copy the file into the pod, and empty the database folder: a newer version can write files that the restore of an older version cannot open. Then start the restore in the background, so that it continues if your connection stops:

   ```sh
   kubectl exec -i platforma-restore -n platforma -- \
     sh -c 'cat > /tmp/backup.tsv.gz' < <backup-file>


   kubectl exec platforma-restore -n platforma -- \
     find /data/database -mindepth 1 -maxdepth 1 ! -name lost+found -exec rm -rf {} +


   kubectl exec platforma-restore -n platforma -- sh -c \
     'nohup sh -c "/app/platforma --restore-db=/tmp/backup.tsv.gz --db-dir=/data/database --force && echo RESTORE OK || echo RESTORE FAILED" > /tmp/restore.log 2>&1 &'
   ```

   The restore takes from minutes to hours: this depends on the size of the database. To see the progress:

   ```sh
   kubectl exec platforma-restore -n platforma -- tail -5 /tmp/restore.log
   ```

   Result: the last line is `RESTORE OK`. Then delete the pod: `kubectl delete pod platforma-restore -n platforma`. If the last line is `RESTORE FAILED`, keep the pod and send `/tmp/restore.log` to MiLaboratories support.

4. **Start the Backend.** After a failed upgrade, deploy the old version: see [Go back to the old version](/maintain-upgrading/#go-back-to-the-old-version). In all other cases:

   ```sh
   kubectl scale deployment platforma -n platforma --replicas=1
   ```

   Result: the Backend pod is `Running` and `Ready`. In the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), an existing project opens with its results.

#### Variant: Single Server

**From a backup file** (an automatic backup):

1. **Stop the Backend:** `sudo systemctl stop platforma`.

2. **Check that the Backend stopped.**

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) stopped:

   ```sh
   systemctl is-active platforma
   pgrep -fa /opt/platforma/binaries/platforma
   ```

   Result: the first command prints `inactive`, and the second command prints nothing. If a process is still there, wait and run the commands again. Do not continue while the process exists: it can still write to the database.

3. **Restore the backup.** Move the database folder aside, and make the database again from the file:

   ```sh
   sudo mv /data/platforma/rocksdb /data/platforma/rocksdb.before-restore
   sudo -u platforma /opt/platforma/binaries/platforma \
     --restore-db=<backup-file> --db-dir=/data/platforma/rocksdb --force
   ```

   The restore takes from minutes to hours: this depends on the size of the database. Result: the output has the line `Database restored successfully`. Delete `/data/platforma/rocksdb.before-restore` when the Backend works again.

4. **Start the Backend:** `sudo systemctl start platforma`.

**From an archive** of [Make a backup now](#make-a-backup-now):

1. **Stop the Backend:** `sudo systemctl stop platforma`.

2. **Check that the Backend stopped.**

   Check that the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) stopped:

   ```sh
   systemctl is-active platforma
   pgrep -fa /opt/platforma/binaries/platforma
   ```

   Result: the first command prints `inactive`, and the second command prints nothing. If a process is still there, wait and run the commands again. Do not continue while the process exists: it can still write to the database.

3. **Put back the data folder** from the archive:

   ```sh
   sudo mv /data/platforma /data/platforma.before-restore
   sudo tar -xzf <archive> -C / data/platforma
   ```

   If the archive does not have any results, also put back the primary storage. Files that the Backend wrote after the backup can stay: no project refers to them.

   ```sh
   sudo rsync -a <backup-place>/primary/ /data/platforma/primary/
   sudo chown -R platforma:platforma /data/platforma
   ```

   Result: `/data/platforma` has the content of the archive. Delete `/data/platforma.before-restore` when the Backend works again.

4. **Start the Backend:** `sudo systemctl start platforma`.

## Next

- [Upgrade Platforma](/maintain-upgrading/)
- [Migrate from server to cloud](/maintain-migrating-to-cloud/)

Source: https://docs.platforma.bio/maintain-backup-and-restore/
