> For the complete documentation index, see [llms.txt](https://docs.akamas.io/akamas-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akamas.io/akamas-docs/managing-akamas/upgrade/migration-procedures.md). Agents can also search and read this documentation through its [MCP server](https://docs.akamas.io/akamas-docs/~gitbook/mcp).

# Migration Procedures

## From 3.6 to 4.0

The upgrade from Akamas Studio 3.6 to 4.0 requires:

* Upgrading the database to a new major version
* Upgrading the CSV telemetry provider configuration

Those upgrades both involve some manual steps.

### Pre-upgrade steps

{% hint style="warning" %}
Run these steps **before** updating the docker-compose or helm release
{% endhint %}

#### Database upgrade

Here's the guide for the database upgrade

<details>

<summary>DB upgrade - Docker version</summary>

{% hint style="info" %}
Make sure you are logged in to the host running the Akamas instance before running the following commands.
{% endhint %}

**Stop the services**

Stop the Akamas services except the databases:

```bash
cd akamas
docker compose down
docker compose up -d database airflow-db kong-database
```

**Export AWS credentials and login to AWS docker repo**

```bash
export AWS_ACCESS_KEY_ID=AAAAAAAAAAA ## use your AWS access key ID
export AWS_SECRET_ACCESS_KEY=bbbbbbbbbbbbbbbbbb ## use your AWS secret access key id
aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 485790562880.dkr.ecr.us-east-2.amazonaws.com

```

**Extract the database passwords**

```bash
docker compose config | python3 -c 'import sys, yaml; s=yaml.safe_load(sys.stdin)["services"]; [print(k+"_DB_PASSWORD="+s[v]["environment"]["POSTGRES_PASSWORD"]) or print(k+"_DB_USER="+s[v]["environment"].get("POSTGRES_USER", "postgres")) for k, v in {"AKAMAS": "database", "AIRFLOW": "airflow-db"}.items()]' > pass.env
```

**Dump the database**

```bash
export PG_IMAGE='485790562880.dkr.ecr.us-east-2.amazonaws.com/akamas/master-db:1.13.0'

mkdir -p backup
source pass.env

echo " *** Dumping akamas services"
docker run --rm \
    --network akamas \
    -u "$(id -u):$(id -g)" \
    -v $(pwd)/backup:/backup \
    -e PGHOST=database \
    -e PGUSER=${AKAMAS_DB_USER} \
    -e PGPASSWORD=${AKAMAS_DB_PASSWORD} \
    "$PG_IMAGE" \
    pg_dumpall --clean --if-exists --exclude-database=postgres -f /backup/akamas_dump.sql

echo " *** Dumping airflow"
docker run --rm \
    --network akamas \
    -u "$(id -u):$(id -g)" \
    -v $(pwd)/backup:/backup \
    -e PGHOST=airflow-db \
    -e PGUSER=${AIRFLOW_DB_USER} \
    -e PGPASSWORD=${AIRFLOW_DB_PASSWORD} \
    "$PG_IMAGE" \
    pg_dump --clean --if-exists -d airflow -f /backup/airflow_dump.sql
```

**Clean up old database**

```bash
echo " *** Removing old containers"
docker rm -fv database airflow-db kong-db
echo " *** Removing old volumes"
docker volume rm -f akamas_airflow-db-data akamas_database-data akamas_kong-data
```

**Start the updated database**

Update `docker-compose.yml` to use the new database image. Back up the old file and replace the image version using `sed`:

```bash
OLD_VERSION=$(python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin)["services"]["database"]["image"].split(":")[1])' < docker-compose.yml)
echo "Current database image version: $OLD_VERSION"
cp docker-compose.yml docker-compose.yml.bak$(date +%s)
sed -i "s|master-db:${OLD_VERSION}|master-db:${PG_IMAGE##*:}|g" docker-compose.yml
diff -u docker-compose.yml.bak* docker-compose.yml
```

Verify the update and start the new database:

```bash
docker compose pull
docker compose up -d database
docker logs -f database
```

Then wait for the message `database system is ready to accept connections` to appear then press CTRL+C.\
NOTE: if the expected message doesn't pop up after a couple of minutes and you see the message `database system was shut down`, instead, some random bug occurred. In this case press CTRL+C then stop the database with `docker compose down`. Then relaunch the last 2 commands above (`docker compose up -d database` and `docker logs -f database` and wait again for the message `database system is ready to accept connections` to appear then press CTRL+C.

**Restore the data**

```bash
docker run --rm \
    --network akamas \
    -v $(pwd)/backup:/backup \
    -e PGHOST=database \
    -e PGUSER=${AKAMAS_DB_USER} \
    -e PGPASSWORD=${AKAMAS_DB_PASSWORD} \
    "$PG_IMAGE" \
    psql -X -f /backup/akamas_dump.sql

docker run --rm \
    --network akamas \
    -v $(pwd)/backup:/backup \
    -e PGHOST=database \
    -e PGUSER=${AKAMAS_DB_USER} \
    -e PGPASSWORD=${AKAMAS_DB_PASSWORD} \
    "$PG_IMAGE" \
    psql -X -f /backup/airflow_dump.sql
```

**Restart Akamas**

Replace `docker-compose.yml` with the latest Akamas 4.0 version, as described in Install the Akamas Server, and restart the remaining services:

```bash
docker compose pull
docker compose up -d
```

</details>

<details>

<summary>DB upgrade - Kubernetes version</summary>

{% hint style="info" %}
Make sure you are using the correct namespace for the Akamas installation. To switch namespaces, run `kubectl config set-context --current --namespace <akamas>`, replacing `<akamas>` with your namespace name.
{% endhint %}

**Check `preStop` hooks**

Ensure the current chart already supports `preStop` hooks for Postgres. Run:

```bash
kubectl get statefulset/database -o jsonpath='{.spec.template.spec.containers[].lifecycle}'
```

If the output contains `preStop`, like in the example below, your chart already supports graceful shutdown and no patching is needed.

```json
{"preStop":{"exec":{"command":["/bin/sh","-c","PGUSER=postgres pg_ctl stop -m fast"]}}}
```

If the output is empty or missing the `preStop` entry, patch the statefulset with:

```bash
kubectl patch statefulset database -p '{"spec":{"template":{"spec":{"terminationGracePeriodSeconds":60,"containers":[{"name":"postgresql","lifecycle":{"preStop":{"exec":{"command":["/bin/sh","-c","PGUSER=postgres pg_ctl stop -m fast"]}}}}]}}}}'
kubectl wait statefulset/database --for=jsonpath='{.status.availableReplicas}=1'
```

**Stop the services**

Stop the Akamas services:

```bash
kubectl scale deployment --all --replicas 0
kubectl scale statefulsets -l 'app.kubernetes.io/name notin (postgresql)' --replicas 0
```

Charts `1.6.4` and later stop all pods except the database automatically. For older charts, scale the database back up manually:

```bash
kubectl scale statefulset database --replicas 1
kubectl wait statefulset/database --for=jsonpath='{.status.availableReplicas}=1'
```

**Dump the database**

Dump the database into a dedicated volume using the job defined in the attached `pg16_dump.yaml` file. It creates a 10Gi PersistentVolumeClaim to store the backup. If your database needs larger storage, update the PVC definition in the YAML file.

```bash
kubectl apply -f pg16_dump.yaml
kubectl wait job/pg-dump --for=jsonpath='{.status.ready}=1' -o template='{{"initContainer complete\n"}}'
kubectl logs job/pg-dump -f --all-containers=true
```

Once the dump completes, scale down the database:

```bash
kubectl scale statefulset database --replicas 0
```

**Clean up the datadir**

Verify the database is scaled down before proceeding:

```bash
kubectl wait statefulset/database --for=jsonpath='{.status.replicas}=0' --timeout=5s && echo Ok || echo 'ERROR: database is still running'
```

Then clean up the datadir using the attached `pg16_cleanup.yaml` file:

```bash
kubectl apply -f pg16_cleanup.yaml
kubectl wait job/pg-cleanup --for=jsonpath='{.status.ready}=1' -o template='{{"initContainer complete\n"}}'
kubectl logs job/pg-cleanup -f --all-containers=true
```

{% hint style="info" %}
You can inspect the content of the backup volume using the `pg-debug` pod

```bash
kubectl apply -f pg16_debug.yaml
```

{% endhint %}

**Upgrade the database**

Once the cleanup completes, patch the statefulset with the new image:

```bash
export PG16_IMAGE='16.6.0-debian-12-r2'
kubectl patch statefulset database -p '{"spec":{"template":{"spec":{"containers":[{"name":"postgresql","image":"485790562880.dkr.ecr.us-east-2.amazonaws.com/akamas/bitnami/postgresql:'${PG16_IMAGE}'"}]}}}}'
kubectl scale statefulset/database --replicas=1
kubectl wait statefulset/database --for=jsonpath='{.status.availableReplicas}=1'
kubectl logs statefulset/database --all-containers=true
```

**Restore the database**

Restore the database using the attached `pg16_restore.yaml` file:

```bash
kubectl apply -f pg16_restore.yaml
kubectl wait job/pg-restore --for=jsonpath='{.status.ready}=1' -o template='{{"initContainer complete\n"}}'
kubectl logs job/pg-restore -f --all-containers=true
```

**Restart the Akamas services**

To complete the upgrade, restart the Akamas services:

```bash
kubectl scale deployment --all --replicas 1
kubectl scale statefulsets --all --replicas 1
```

**Upgrade the Akamas release**

Once verified that the new database is working correctly, upgrade Akamas using the chart associated with the latest 4.0 release, as described in Install Akamas:

```bash
helm upgrade --install \
    --create-namespace --namespace akamas \
    --repo http://helm.akamas.io/charts \
    --version '<1.9.0>' \
    -f akamas.yaml \
    akamas akamas
```

**Final cleanup**

Once you have verified that the instance was upgraded successfully and works correctly, you can delete the backup volume.

```bash
kubectl delete pvc pg-dump
```

</details>

### Post-upgrade steps

{% hint style="warning" %}
Run these steps **after** updating the docker-compose or helm release
{% endhint %}

#### CSV telemetry provider configuration upgrade

This step upgrades the configuration (adding new config parameters: hostname, username, and password) of the CSV telemetry provider. If you have never used this provider in your studies (or systems) and have no CSV telemetry instance defined in any system, we recommend the faster way:

<details>

<summary>Recommended procedure when no CSV telemetry instances are present</summary>

An important prerequisite for this procedure is to start the services beforehand (see the final part of #from-3.6-to-3.7), since you need the telemetry service running.

Log in with Akamas CLI to your environment with:

```
 akamas login
```

Then issue the following command:

```
akamas uninstall tp "CSV File"
```

**VERY IMPORTANT:** If a message appears telling `It will also delete the following telemetry-instances:`

like in the following example:

```bash
$> akamas uninstall tp "CSV File"
This command will delete telemetry provider 'CSV File'.
It will also delete the following telemetry-instances:
                 id                    workspace           system                     name
====================================================================================================
0f13e9b9-c110-46a8-9bb1-c53fe2e6c199   default     renaissance               CSV File telem instance
e86a3e01-11a9-4a35-bcf1-ead3e492afeb   work1       customerpay-bff-service   CSV File
b22a72e0-7013-4ac0-84a3-7cc337ba0d73   work2       Mongo                     CSV File 2
2c257de0-faca-445b-b7ac-81044c239efb   work3       renaissance               CSV File telem instance

Do you want to proceed? [y/N]:
```

Just STOP this procedure by pressing ENTER key and refer to alternate Docker or kubernetes procedures below.\
If there are no telemetry instances to delete, you may proceed with the deletion of the telemetry provider (press 'y' then ENTER), then you can recreate the new telemetry provider by creating a new file named `csv-file-provider-official.yaml`

with these exact contents:

```yaml
name: CSV File
description: Telemetry provider to collect metrics from CSV files
dockerImage: 485790562880.dkr.ecr.us-east-2.amazonaws.com/akamas/telemetry-providers/csv-file-provider:3.3.0
```

then issuing the following command:

```bash
akamas install tp csv-file-provider-official.yaml
```

</details>

These, instead, are the alternate procedures for the Docker and kubernetes case, for use when you already have CSV telemetry instances defined in your systems. They have the advantage that you don't need Akamas Studio services to be up and running (you only need a database, already running)

<details>

<summary>Alternate procedure for Docker</summary>

Log in to the machine where akamas is installed via SSH. Then issue the command:

```bash
cd akamas
```

Retrieve the telemetry DB password with this command:

```bash
docker compose exec telemetry bash -c "echo \$SPRING_DATASOURCE_PASSWORD  "
```

Connect to the database container shell with:

```bash
docker compose exec -it database bash
```

Connect to postgres with:

```bash
psql -U akamas_telemetry -p -d telemetry_service -p 5432
```

Then type the DB password (retrieved above) when asked.

Then issue SQL command:

```sql
update provider set config = '[{"required": false, "paramName": "logLevel", "paramType": "STRING_ENUM", "protected": false, "validationParams": {"validStrings": ["INFO", "DETAILED"]}}, {"required": true, "paramName": "remoteFilePattern", "paramType": "STRING", "protected": false}, {"required": true, "paramName": "hostname", "paramType": "IP_OR_FQDN", "protected": false, "requiredAlternates": ["address"]}, {"required": false, "paramName": "port", "paramType": "INTEGER", "protected": false, "validationParams": {"max": 65563, "min": 1}}, {"required": true, "paramName": "username", "paramType": "STRING", "protected": false}, {"required": true, "paramName": "password", "paramType": "STRING", "protected": true, "requiredAlternates": ["auth", "key"]}, {"required": true, "paramName": "key", "paramType": "STRING", "protected": true, "requiredAlternates": ["password", "auth"]}, {"required": true, "paramName": "authType", "paramType": "STRING_ENUM", "protected": false, "validationParams": {"validStrings": ["password", "key"]}, "requiredAlternates": ["password", "key"]}, {"required": false, "paramName": "protocol", "paramType": "STRING_ENUM", "protected": false, "validationParams": {"validStrings": ["scp", "sftp"]}}, {"required": false, "paramName": "componentColumn", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "componentName", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "timestampColumn", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "timestampFormat", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "filenamePattern", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "fieldSeparator", "paramType": "STRING", "protected": false, "validationParams": {"regex": "[,;\t]"}}, {"required": false, "paramName": "labelColumns", "paramType": "STRING_LIST", "protected": false}]' where name = 'CSV File';
```

</details>

<details>

<summary>Alternate procedure for Kubernetes</summary>

Properly configure your `kubectl` configuration in order to connect to the correct cluster and namespace holding your Akamas installation.

Retrieve telemetry DB password with:

```bash
kubectl get secret database-user-credentials -o go-template='{{ .data.telemetry | base64decode }} '
```

Connect to database pod shell with:

```bash
kubectl exec -it database-0 -- bash
```

Connect to postgres with:

```bash
psql -U akamas_telemetry -p -d telemetry_service -p 5432
```

then type in DB password (retrieved above) when asked.

Then issue SQL command:

```sql
update provider set config = '[{"required": false, "paramName": "logLevel", "paramType": "STRING_ENUM", "protected": false, "validationParams": {"validStrings": ["INFO", "DETAILED"]}}, {"required": true, "paramName": "remoteFilePattern", "paramType": "STRING", "protected": false}, {"required": true, "paramName": "hostname", "paramType": "IP_OR_FQDN", "protected": false, "requiredAlternates": ["address"]}, {"required": false, "paramName": "port", "paramType": "INTEGER", "protected": false, "validationParams": {"max": 65563, "min": 1}}, {"required": true, "paramName": "username", "paramType": "STRING", "protected": false}, {"required": true, "paramName": "password", "paramType": "STRING", "protected": true, "requiredAlternates": ["auth", "key"]}, {"required": true, "paramName": "key", "paramType": "STRING", "protected": true, "requiredAlternates": ["password", "auth"]}, {"required": true, "paramName": "authType", "paramType": "STRING_ENUM", "protected": false, "validationParams": {"validStrings": ["password", "key"]}, "requiredAlternates": ["password", "key"]}, {"required": false, "paramName": "protocol", "paramType": "STRING_ENUM", "protected": false, "validationParams": {"validStrings": ["scp", "sftp"]}}, {"required": false, "paramName": "componentColumn", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "componentName", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "timestampColumn", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "timestampFormat", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "filenamePattern", "paramType": "STRING", "protected": false}, {"required": false, "paramName": "fieldSeparator", "paramType": "STRING", "protected": false, "validationParams": {"regex": "[,;\t]"}}, {"required": false, "paramName": "labelColumns", "paramType": "STRING_LIST", "protected": false}]' where name = 'CSV File';
```

</details>

After using one of the two alternate procedures, you MUST upgrade the CSV Telemetry Provider to the latest version 3.3.0 (the 3.2.0 version that was shipped with 3.6.x will not work properly when using new features). For this, you need to start up services beforehand (refer to #from-3.6-to-3.7). Then you can upgrade the CSV telemetry provider by:\
Creating a new file named `csv-file-provider-official.yaml` with these contents:

```yaml
name: CSV File
description: Telemetry provider to collect metrics from CSV files
dockerImage: 485790562880.dkr.ecr.us-east-2.amazonaws.com/akamas/telemetry-providers/csv-file-provider:3.3.0
```

and run:

```bash
akamas install tp -u csv-file-provider-official.yaml
```

## From 4.0 to 4.1.0

The upgrade from Akamas Studio 4.0 to 4.1.0 requires:

* Upgrading the Postgres database to a new image (only for Kubernetes case)
* Upgrading ElasticSearch to a new major version

Those upgrades involve several manual steps.

### Upgrade steps

{% hint style="warning" %}
Running these steps actually perfroms both the pre-update an the update so you don't need to go back to the previous 4.1.0 update pages after using this migration guide
{% endhint %}

#### Database + ElasticSearch upgrade

Here's the guide for the database + ElasticSearch upgrade

<details>

<summary>Kubernetes upgrade</summary>

{% hint style="info" %}
Make sure you are using the correct namespace for the Akamas installation. To switch namespaces, run `kubectl config set-context --current --namespace <akamas>`, replacing `<akamas>` with your namespace name.
{% endhint %}

### **DB migration from old to new image**

If you're using Kubernetes (not Openshift), download the migration file below

{% file src="/files/gySem6MeA1uaWzjLauwJ" %}

If you're, instead, using Openshift, download the migration file below

{% file src="/files/mKXHzvzdeU93ryfFbr4f" %}

Ensure that in current Akamas Studio 4.0.x version there are no custom changes to file pg\_hba.conf on the database pod. Run command:

```bash
kubectl exec database-0 -- cat /opt/bitnami/postgresql/conf/pg_hba.conf
```

And ensure that it contains the following 5 lines (ignore line ordering)

```
host all all 0.0.0.0/0 md5
host all all ::/0 md5
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
```

If there are more lines, add them to downloaded file fix-pg-hba.yaml just before line 22 (the line with `---` making sure that you add 2 blanks for indentation to every missing line you add into this YAML file.

Then stop all service/deployments and database+airflow statefulset with:

```bash
kubectl scale deployment --all --replicas 0
kubectl scale statefulset database airflow-scheduler --replicas 0
kubectl wait --for=delete pod/database-0 pod/airflow-scheduler-0 --timeout=120s
```

Then run the following command:

```bash
kubectl get pods
```

and check if it elasticsearch-master-0 is the only pod still running.

Finally, apply the YAML file that you downloaded above to fix file pg\_hba.conf on database volume with one of the the following commands (depending on Kubernetes or Openshift):

```bash
# use this line ONLY if you downloaded Kubernetes file
kubectl apply -f fix-pg-hba.yaml
# use this line ONLY if you downloaded Openshift file
kubectl apply -f fix-pg-hba-openshift.yaml
```

### **ElasticSearch migration**

This section describes the steps needed to migrate all ElasticSearch logs from old 7.x version to new 9.x version. The process includes backing up the existing indices (step 1,2 and 3), deleting the old volume (step 4), migrate to the new kubernetes chart, restore original indices (step 7) and verify them (step 8)

However, if you decide old logs aren't needed you can simply skip all first 3 steps and go straight to step 4 (this means: doing no backup at all and delete elasticsearch volume since at some point it must recreated anyway as a fresh one) then also skip step 7 and 8 since you will have no backup.

{% hint style="danger" %}
Skipping the backup/restore process and just deleting the ElastiCSearch volume is a destructive operation and you will lose all stored logs and stored chart data points. Do this ONLY if you're REALLY not interested in keeping task logs and chart data from previous study runs of Akamas Studio 3.x
{% endhint %}

#### Step 1 — Record the source state

This step is necessary because you cannot verify the migration afterwards without gathering these metrics. Run the following command in another terminal:

```bash
kubectl port-forward svc/elasticsearch 9200:9200 &
```

Then, on original terminal, run:

```bash
curl -s "http://localhost:9200/_cat/indices?v&s=index"
curl -s "http://localhost:9200/_cat/aliases?v"
```

Note the `docs.count` of `data_point` and of every `akamas-logs-*` index.

#### Step 2 — Ensure writes are frozen

Confirm the counts from step 1 have stopped moving before dumping. On a live instance\
they drift continuously — a dump taken against an unfrozen cluster silently misses\
whatever is written after the scroll passes. If you gather index+aliases metrics again, make sure they haven't changed before proceeding. Since services are already down, they shouldn't have changed.

#### Step 3 — Dump

Download utility file es-migrate.sh and file akamas-logs-template.json and retained-logs.json from links below:

{% file src="/files/kiyidL1jX7M54uWMkAka" %}

{% file src="/files/cp3ocw7OCaWoIXUuRIR4" %}

{% file src="/files/oGAHXUVTulGx0p4z32YU" %}

and place them in current folder. Then run the script below:

{% hint style="info" %}
This process will take time, expecially datapoints migration, due to the high number of docs involved. Dumping 100k docs can easily take a couple of minutes, as well as dumping 1M docs can take a 20 minutes
{% endhint %}

```bash
# shell file cannot be stored as is on gitbook so we gzipped it and it must be ungzipped
gzip -d ./es-migrate.sh.gz
chmod +x ./es-migrate.sh
export DUMP_DIR=~/akamas-es9-migration    # durable storage
mkdir -p "$DUMP_DIR"
./es-migrate.sh dump http://localhost:9200 data_point "$DUMP_DIR/data_point.jsonl.gz"
./es-migrate.sh dump http://localhost:9200 'akamas-logs-*' "$DUMP_DIR/logs.jsonl.gz" --query-file retained-logs.json
```

Each command prints the document count it wrote. `data_point` must match step 2 exactly. The log count will be lower than step 2: that is the filter working.

**The dump files are your only backup from here on.** Keep them until the migration is verified. For extra safety, snapshot the Elasticsearch volume before step 4.

#### Step 4 — Wipe the Elasticsearch data volume

Scale down elasticsearch first, then delete the PVC whose contents you just backed up

<pre class="language-bash"><code class="lang-bash"><strong>kubectl scale sts/elasticsearch-master --replicas=0
</strong>kubectl wait --for=delete pod/elasticsearch-master-0 --timeout=120s
kubectl delete pvc elasticsearch-master-elasticsearch-master-0
</code></pre>

#### **Step 5 — Upgrade to new chart**

Now we must update the local chart repository which, in **online** mode, is done with:

```bash
# update local repo
helm repo update akamas
# perform the upgrade to Akamas Studio 4.1.0 (chart version 1.9.0)
helm upgrade \
  --repo http://helm.akamas.io/charts \
  --version '1.9.0' \
  -f akamas.yaml \
  akamas akamas
```

but in **offline** (air-gapped) mode should be done by following the guide at [Offline Installation - Private registry](https://docs.akamas.io/akamas-docs/installing/kubernetes/install-akamas/offline.md) but stopping just before [Offline Installation - Private registry](https://docs.akamas.io/akamas-docs/installing/kubernetes/install-akamas/offline.md#start-the-installation). In fact, where it says to launch an `helm pull --repo` command, you use instead (almost same command but different version):

```bash
# update local repo
helm pull --repo http://helm.akamas.io/charts --version '1.9.0' akamas
# then you can perform the upgrade to Akamas Studio 4.1.0 (chart version 1.9.0)
helm upgrade \
  -f akamas.yaml \
  akamas akamas-1.9.0.tgz
```

#### Step 6 — Wait for the services to initialise their indices

**Do not reload old indices/aliases yet.** Two indices are created for you, and loading ahead of either one produces a degraded index that nothing repairs later, with no error at load time:

| Wait for service | Because                                                                                                                                                                                                                                                                                                 |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `metrics`        | It creates `data_point` with the real mapping and `number_of_replicas: 0`. If the load's `_bulk` auto-creates it instead, the index gets pure dynamic mapping **and 1 replica**, which pins a single-node cluster to `yellow` permanently.                                                              |
| `logstash`       | It installs the `akamas-logs-*` index template, which supplies the `akamas-logs` alias. Daily log indices are created implicitly by the `_bulk` write, so without the template they get dynamic mapping and **no alias** — and log\_service reads through that alias, so the UI renders no logs at all. |

To be sure services are up and running, wait for a minute then issue the following command to wait for services logstash and metrics to come up:

```bash
kubectl wait --for=condition=Ready pod -l 'service in (logstash,metrics)' --timeout=1200s
```

At this point the old elasticsearch portforward should have gone, so on the same terminal you used before to launch the portforward, rerun a new portforward on the new elasticsearch service with:

```bash
kubectl port-forward svc/elasticsearch 9200:9200 &
```

Then go back to the previous terminal and run:

```bash
curl -s "http://localhost:9200/_cat/indices?v"
curl -s "http://localhost:9200/_index_template/akamas-logs-template" | jq -e .index_templates
```

And ensure both commands answer with no error.

#### Step 7 — Load

Run these commands in order:

{% hint style="info" %}
This process takes time, especially for datapoints, due to the high number of documents involved. Even when the script runs with only 0.1 CPU, the load restores about 1,000 documents per second (1M documents in roughly 15 minutes); with more CPU it is bound by Elasticsearch. Run long loads with `nohup ... &` (or inside `tmux`), so that a dropped terminal session does not cost you their output.
{% endhint %}

<pre class="language-bash"><code class="lang-bash"><strong>./es-migrate.sh ensure-logs-template http://localhost:9200
</strong>./es-migrate.sh load http://localhost:9200 "$DUMP_DIR/data_point.jsonl.gz" --index data_point
./es-migrate.sh load http://localhost:9200 "$DUMP_DIR/logs.jsonl.gz"
./es-migrate.sh ensure-logs-alias http://localhost:9200
</code></pre>

* `ensure-logs-template` / `ensure-logs-alias` are a fallback for when logstash has not installed the template. Both are no-ops when it has, so run them unconditionally.
* `--index data_point` sends every document to `data_point`, keeping the id it had in Elasticsearch 7.
* The log load (no `--index`) restores each document into its original daily index with its original id.
* **Both loads are idempotent.** Every document is written with a `create` operation and a fixed id, so re-running a load is safe: documents already present return 409 and are skipped. To resume an interrupted load, run the same command again.
* Batches rejected by Elasticsearch back-pressure (HTTP 429) or lost to a network error are retried automatically.
* `load` exits non-zero if any non-409 bulk error remains, printing the distinct reasons. Fix the cause and run the same command again.

#### Step 8 — Verify

```bash
curl -s "http://localhost:9200/_refresh" >/dev/null
curl -s "http://localhost:9200/_cat/indices?v&s=index"   # counts vs steps 1 and 3
curl -s "http://localhost:9200/_cat/aliases?v"           # every akamas-logs-* index listed
curl -s "http://localhost:9200/_cluster/health?pretty"   # status green, not yellow
```

Then in the UI:

* open a study that predates the migration and confirm its metric charts render;
* open one of its trials and confirm the workflow-task log renders;
* confirm a telemetry-provider log renders.

A `yellow` cluster means `data_point` was auto-created with a replica — see step 6. Log indices missing from `_cat/aliases` means the template was absent at load time; run `ensure-logs-alias`.

Once verified, decommission any retained snapshot and archive the dump files.

#### Cleanup

Delete the temporary configmap with:

```bash
kubectl delete configmap fix-pg-hba
```

</details>

<details>

<summary>Docker upgrade</summary>

{% hint style="info" %}
From a terminal, log onto the docker machine with ssh then, once inside the home folder, change to subfolder `akamas` (it will contain file `docker-compose.yml`)
{% endhint %}

### **DB migration**

This process is not necessary in docker case

### **ElasticSearch migration**

This section describes the steps needed to migrate all ElasticSearch logs from old 7.x version to new 9.x version. The process includes backing up the existing indices (step 1,2 and 3), deleting the old volume (step 4), migrate to the new version, restore original indices (step 7) and verify them (step 8)

However, if you decide old logs aren't needed you can simply skip all first 3 steps and go straight to step 4 (this means: doing no backup at all and delete elasticsearch volume since at some point it must recreated anyway as a fresh one) then also skip step 7 and 8 since you will have no backup.

{% hint style="danger" %}
Skipping the backup/restore process and just deleting the ElastiCSearch volume is a destructive operation and you will lose all stored logs and stored chart data points. Do this ONLY if you're REALLY not interested in keeping task logs and chart data from previous study runs of Akamas Studio 3.x
{% endhint %}

#### Prerequisite — Stop all other containers

Stop all docker containers and restart only elasticSearch with:

```bash
docker compose down
docker compose up -d elasticsearch
```

Then run the following command:

```bash
docker compose ps
```

and check if it elasticsearch is the only container still running.

#### Step 1 — Record the source state

This step is necessary because you cannot verify the migration afterwards without gathering these metrics. Run the following command to access elasticsearch container:

```bash
docker compose exec -it elasticsearch bash
```

Then, from inside the elasticsearch container prompt, run:

<pre class="language-bash"><code class="lang-bash"><strong>curl -s "http://localhost:9200/_cat/indices?v&#x26;s=index"
</strong>curl -s "http://localhost:9200/_cat/aliases?v"
</code></pre>

Note the `docs.count` of `data_point` and of every `akamas-logs-*` index.

#### Step 2 — Ensure writes are frozen

Confirm the counts from step 1 have stopped moving before dumping. On a live instance\
they drift continuously — a dump taken against an unfrozen cluster silently misses\
whatever is written after the scroll passes. If you gather index+aliases metrics again, make sure they haven't changed before proceeding. Since services are already down, they shouldn't have changed.

Then exit from the elasticsearch container prompt with:

```bash
exit 
```

You will be back at the original `akamas` folder containing the `docker-compose.yaml` file.

#### Step 3 — Dump

Download utility file es-migrate.sh and file akamas-logs-template.json and retained-logs.json from links below:

{% file src="/files/kiyidL1jX7M54uWMkAka" %}

{% file src="/files/cp3ocw7OCaWoIXUuRIR4" %}

{% file src="/files/oGAHXUVTulGx0p4z32YU" %}

and place them on the Akamas Studio instance in `/tmp` folder.

Now you should copy these 3 files inside the elasticsearch container with:

```bash
docker compose cp /tmp/es-migrate.sh.gz elasticsearch:/tmp/
docker compose cp /tmp/akamas-logs-template.json elasticsearch:/tmp/
docker compose cp /tmp/retained-logs.json elasticsearch:/tmp/
```

and get again inside the elasticsearch container prompt with:

```bash
docker compose exec -it elasticsearch bash
```

Then, from inside the container, run the preparation commands below:

```bash
apt update
# script es-migrate needs jq
apt install jq -y
cd /tmp/
gzip -d ./es-migrate.sh.gz
chmod +x ./es-migrate.sh
```

Then run the dump commands below:

{% hint style="info" %}
This process will take time, expecially datapoints migration, due to the high number of docs involved. Dumping 100k docs can easily take a couple of minutes, as well as dumping 1M docs can take a 20 minutes
{% endhint %}

```bash
export DUMP_DIR=/tmp/akamas-es9-migration
mkdir -p "$DUMP_DIR"
./es-migrate.sh dump http://localhost:9200 data_point "$DUMP_DIR/data_point.jsonl.gz"
./es-migrate.sh dump http://localhost:9200 'akamas-logs-*' "$DUMP_DIR/logs.jsonl.gz" --query-file retained-logs.json
```

Each command prints the document count it wrote. `data_point` must match step 2 exactly. The log count will be lower than step 2: that is the filter working.

Now compress all dump files for later use and copy the resulting archive back to the Akamas Studio machine for the susequent restore with:

```bash
# compress all files for later
tar cvfz es7-dump.tgz es-migrate.sh akamas-logs-template.json retained-logs.json akamas-es9-migration/
# exit elasticsearch terminal and go back to local Amazon Studio machine
exit
# and copy the dump to local Amazon Studio machine
docker compose cp elasticsearch:/tmp/es7-dump.tgz ~/akamas/
# ensure the file has been copied succesfully
ls -la ~/akamas/es7-dump.tgz
```

**The dump archive is your only backup from here on.** Keep it until the migration is verified. For extra safety, you can optionally snapshot the full elasticsearch 7.x volume before step 4 with the following command:

```bash
docker run --rm -v akamas_elastic-data:/data:ro -v $(pwd):/backup alpine tar czf /backup/es7_volume_backup.tar.gz -C /data .
```

#### Step 4 — Wipe the Elasticsearch data volume

Turn off elasticsearch elasticsearch container first, then delete the volume whose contents you just backed up

<pre class="language-bash"><code class="lang-bash"><strong>docker compose down
</strong>docker volume rm akamas_elastic-data
</code></pre>

#### **Step 5 — Upgrade to new version**

Now we must update to the new version which, in **online** mode, is done by following the Akamas Studio 4.0 installation guide [Online installation mode](https://docs.akamas.io/akamas-docs/installing/docker/install-the-akamas-server/online-installation-mode.md) but, in short, it's done with:

```bash
curl -O https://s3.us-east-2.amazonaws.com/akamas/compose/4.1.0/docker-compose.yml
docker compose up -d
```

but in **offline** (air-gapped) mode it should be done by following the guide at [Offline installation mode](https://docs.akamas.io/akamas-docs/installing/docker/install-the-akamas-server/offline-installation-mode.md)

#### Step 6 — Wait for the services to initialise their indices

**Do not reload old indices/aliases yet.** Two indices are created for you, and loading ahead of either one produces a degraded index that nothing repairs later, with no error at load time:

| Wait for service | Because                                                                                                                                                                                                                                                                                                 |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `metrics`        | It creates `data_point` with the real mapping and `number_of_replicas: 0`. If the load's `_bulk` auto-creates it instead, the index gets pure dynamic mapping **and 1 replica**, which pins a single-node cluster to `yellow` permanently.                                                              |
| `logstash`       | It installs the `akamas-logs-*` index template, which supplies the `akamas-logs` alias. Daily log indices are created implicitly by the `_bulk` write, so without the template they get dynamic mapping and **no alias** — and log\_service reads through that alias, so the UI renders no logs at all. |

To be sure services are up and running, issue command:

```shellscript
watch -n 5 akamas status
```

and wait until Log service and Metrics service are up then press CTRL+C to exit from le watch loop.

Then check with:

```bash
watch -n 5 docker compose ps logstash
```

and wait until logstash service is up and in healthy status. At this point press CTRL+C to exit again the watch loop.

Now it's the time to copy the dumped archive to elasticsearch container with:

```bash
docker compose cp elasticsearch:/tmp/es7-dump.tgz ~/akamas/
```

and install all missing commands (those needed by `es-migrate`.sh script) inside the elasticsearch container with:

```bash
docker compose exec -u 0 elasticsearch microdnf install -y jq tar gzip
```

then get again inside the elasticsearch container prompt with:

```bash
docker compose exec -it elasticsearch bash
```

Then, from inside the container, run the preparation commands below:

```bash
cd /tmp/
tar xvfz /tmp/es7-dump.tgz
```

en go back to the previous terminal and run:

```bash
curl -s "http://localhost:9200/_cat/indices?v"
curl -s "http://localhost:9200/_index_template/akamas-logs-template" | jq -e .index_templates
```

And ensure both commands answer with no error.

#### Step 7 — Load

Run these commands in order:

{% hint style="info" %}
This process takes time, especially for datapoints, due to the high number of documents involved. Even when the script runs with only 0.1 CPU, the load restores about 1,000 documents per second (1M documents in roughly 15 minutes); with more CPU it is bound by Elasticsearch. Run long loads with `nohup ... &` (or inside `tmux`), so that a dropped terminal session does not cost you their output.
{% endhint %}

<pre class="language-bash"><code class="lang-bash">export DUMP_DIR=/tmp/akamas-es9-migration
<strong>./es-migrate.sh ensure-logs-template http://localhost:9200
</strong>./es-migrate.sh load http://localhost:9200 "$DUMP_DIR/data_point.jsonl.gz" --index data_point
./es-migrate.sh load http://localhost:9200 "$DUMP_DIR/logs.jsonl.gz"
./es-migrate.sh ensure-logs-alias http://localhost:9200
</code></pre>

* `ensure-logs-template` / `ensure-logs-alias` are a fallback for when logstash has not installed the template. Both are no-ops when it has, so run them unconditionally.
* `--index data_point` sends every document to `data_point`, keeping the id it had in Elasticsearch 7.
* The log load (no `--index`) restores each document into its original daily index with its original id.
* **Both loads are idempotent.** Every document is written with a `create` operation and a fixed id, so re-running a load is safe: documents already present return 409 and are skipped. To resume an interrupted load, run the same command again.
* Batches rejected by Elasticsearch back-pressure (HTTP 429) or lost to a network error are retried automatically.
* `load` exits non-zero if any non-409 bulk error remains, printing the distinct reasons. Fix the cause and run the same command again.

#### Step 8 — Verify

```bash
curl -s "http://localhost:9200/_refresh" >/dev/null
curl -s "http://localhost:9200/_cat/indices?v&s=index"   # counts vs steps 1 and 3
curl -s "http://localhost:9200/_cat/aliases?v"           # every akamas-logs-* index listed
curl -s "http://localhost:9200/_cluster/health?pretty"   # status green, not yellow
```

Then in the UI:

* open a study that predates the migration and confirm its metric charts render;
* open one of its trials and confirm the workflow-task log renders;
* confirm a telemetry-provider log renders.

A `yellow` cluster means `data_point` was auto-created with a replica — see step 6. Log indices missing from `_cat/aliases` means the template was absent at load time; run `ensure-logs-alias`.

Once verified, archive the dump files.

#### **Cleanup**

You can now safely remove temporary installed commands from elasticsearch container. Just exit from elasticsearch container with:

```bash
exit
```

Then remove installed executables with:

```bash
docker compose exec -u 0 elasticsearch microdnf remove -y jq tar gzip
```

</details>

## From 4.1.0 to 4.1.1

### Kubernetes

Akamas Studio 4.1.1 (chart 1.9.1) reduces the default size of the Airflow task-log volume from 100 GB to 20 GB. Kubernetes does not allow changing the volume template of an existing StatefulSet, so `helm upgrade` fails with `StatefulSet.apps "airflow-scheduler" is invalid: spec: Forbidden` unless you remove the Airflow scheduler StatefulSet first.

{% hint style="warning" %}
Run this step **before** `helm upgrade`.
{% endhint %}

Delete the StatefulSet while keeping its pod and volume (`--cascade=orphan`). The upgrade recreates it and reattaches the existing 100 GB volume, so no task log is lost:

```bash
kubectl delete statefulset airflow-scheduler --cascade=orphan
```

To keep the existing size instead, set `airflow.workers.persistence.size: 100Gi` in your values file; then this step is not needed.

### Docker

No manual steps are required.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.akamas.io/akamas-docs/managing-akamas/upgrade/migration-procedures.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
