# Upgrade Guide - ScyllaDB 5.4 to 2024.1

This document is a step-by-step procedure for upgrading from ScyllaDB 5.4
to ScyllaDB Enterpise 2024.1, and rollback to version 5.4 if required.

This guide covers upgrading ScyllaDB on Red Hat Enterprise Linux (RHEL) CentOS, Debian,
and Ubuntu. See [OS Support by Platform and Version](https://opensource.docs.scylladb.com/stable/getting-started/os-support.md)
for information about supported versions.

This guide also applies when you’re upgrading ScyllaDB Enterprise official image on EC2,
GCP, or Azure.

## Upgrade Procedure

A ScyllaDB upgrade is a rolling procedure that does **not** require full cluster shutdown.
For each of the nodes in the cluster, you will:

* Check that the cluster’s schema is synchronized
* Drain the node and backup the data
* Backup the configuration file
* Stop ScyllaDB
* Download and install new ScyllaDB packages
* Start ScyllaDB
* Validate that the upgrade was successful

#### CAUTION
Apply the procedure **serially** on each node. Do not move to the next node before
validating that the node you upgraded is up and running the new version.

**During** the rolling upgrade, it is highly recommended:

* Not to use the new 2024.1 features.
* Not to run administration functions, like repairs, refresh, rebuild, or add or remove
  nodes. See [sctool](https://manager.docs.scylladb.com/stable/sctool/) for suspending
  ScyllaDB Manager’s scheduled or running repairs.
* Not to apply schema changes.

#### NOTE
Before upgrading, make sure to use the latest
[ScyllaDB Monitoring](https://monitoring.docs.scylladb.com/) stack.

## Upgrade Steps

### Check the cluster schema

Make sure that all nodes have the schema synchronized before upgrade. The upgrade
procedure will fail if there is a schema disagreement between nodes.

```sh
nodetool describecluster
```

### Drain the nodes and backup the data

Before any major procedure, like an upgrade, it is recommended to backup all
the data to an external device. In ScyllaDB, you can backup the data using
the `nodetool snapshot` command. For **each** node in the cluster, run
the following command:

```sh
nodetool drain
nodetool snapshot
```

Take note of the directory name that nodetool gives you, and copy all the directories
having that name under `/var/lib/scylla` to a backup device.

When the upgrade is completed on all nodes, remove the snapshot with the
`nodetool clearsnapshot -t <snapshot>` command to prevent running out of space.

### Backup the configuration file

```sh
sudo cp -a /etc/scylla/scylla.yaml /etc/scylla/scylla.yaml.backup-src
```

### Gracefully stop the node

```sh
sudo service scylla-server stop
```

### Download and install the new release

Before upgrading, check what version you are running now using `scylla --version`.
You should use the same version as this version in case you want to [rollback](./#rollback-procedure)
the upgrade. If you are not running a 5.4.x version, stop right here!
This guide only covers 5.4.x to 2024.1.y upgrades.

Debian/Ubuntu

**To upgrade ScyllaDB:**

1. Update the ScyllaDB deb repo ([Debian](https://www.scylladb.com/customer-portal/?product=ent&platform=debian-10&version=stable-release-2024.1), [Ubuntu](https://www.scylladb.com/customer-portal/?product=ent&platform=ubuntu-20.04&version=stable-release-2024.1)) to 2024.1
2. Configure Java 1.8:
   > ```console
   > sudo apt-get update
   > sudo apt-get install -y openjdk-8-jre-headless
   > sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
   > ```
3. Install the new ScyllaDB version:
   > ```console
   > sudo apt-get clean all
   > sudo apt-get update
   > sudo apt-get remove scylla\*
   > sudo apt-get install scylla-enterprise
   > sudo systemctl daemon-reload
   > ```

Answer ‘y’ to the first two questions.

RHEL/CentOS

**To upgrade ScyllaDB:**

1. Update the [ScyllaDB rpm repo](https://www.scylladb.com/customer-portal/?product=ent&platform=centos7&version=stable-release-2024.1)  to 2024.1.
2. Install the new ScyllaDB version:
   > ```sh
   > sudo yum clean all
   > sudo rm -rf /var/cache/yum
   > sudo yum remove scylla\*
   > sudo yum install scylla-enterprise
   > ```

**Installing the New Version on Cloud**

If you’re using the ScyllaDB official image (recommended), see the *Debian/Ubuntu*
tab for upgrade instructions. If you’re using your own image and hae installed ScyllaDB
packages for Ubuntu or Debian, you need to apply an extended upgrade procedure:

1. Update the ScyllaDB deb repo (see above).
2. Configure Java 1.8 (see above).
3. Install the new ScyllaDB version with the additional
   `scylla-enterprise-machine-image` package:
   ```default
   sudo apt-get clean all
   sudo apt-get update
   sudo apt-get dist-upgrade scylla-enterprise
   sudo apt-get dist-upgrade scylla-enterprise-machine-image
   ```
4. Run `scylla_setup` without running `io_setup`.
5. Run `sudo /opt/scylladb/scylla-machine-image/scylla_cloud_io_setup`.

### Start the node

```sh
sudo service scylla-server start
```

### Validate

1. Check cluster status with `nodetool status` and make sure **all** nodes, including
   the one you just upgraded, are in `UN` status.
2. Use `curl -X GET "http://localhost:10000/storage_service/scylla_release_version"`
   to check the ScyllaDB version. Validate that the version matches the one you upgraded to.
3. Check scylla-server log (using `journalctl _COMM=scylla`) and `/var/log/syslog`
   to validate there are no new errors in the log.
4. Check again after two minutes to validate that no new issues are introduced.

Once you are sure the node upgrade was successful, move to the next node in the cluster.

## Rollback Procedure

#### NOTE
Execute the following commands one node at a time, moving to the next node only **after** the rollback procedure is completed successfully.

The following procedure describes a rollback from ScyllaDB 2024.1.x to
5.4.y. Apply this procedure if an upgrade from 5.4 to 2024.1
failed before completing on all nodes. Use this procedure only for nodes you upgraded
to 2024.1.

#### WARNING
The rollback procedure can only be applied if some nodes have **not** been upgraded
to 2024.1 yet. As soon as the last node in the rolling upgrade procedure is
started with 2024.1, rollback becomes impossible. At that point, the only way
to restore a cluster to 5.4 is by restoring it from backup.

ScyllaDB rollback is a rolling procedure that does **not** require a full cluster shutdown.
For each of the nodes you rollback to 5.4 you will:

* Drain the node and stop ScyllaDB
* Retrieve the old ScyllaDB packages
* Restore the configuration file
* Restore system tables
* Reload systemd configuration
* Restart ScyllaDB
* Validate the rollback success

Apply the following procedure **serially** on each node. Do not move to the next node before
validating that the rollback was successful and the node is up and running the old version.

## Rollback Steps

### Drain and gracefully stop the node

```sh
nodetool drain
sudo service scylla-server stop
```

### Download and install the old release

Debian/Ubuntu

1. Remove the old repo file.
   > ```sh
   > sudo rm -rf /etc/apt/sources.list.d/scylla.list
   > ```
2. Update the ScyllaDB deb repo ([Debian](http://www.scylladb.com/download/?platform=debian-10&version=scylla-5.4), [Ubuntu](https://www.scylladb.com/download/?platform=ubuntu-20.04&version=scylla-5.4)) to 5.4.
3. Install:
   > ```default
   > sudo apt-get update
   > sudo apt-get remove scylla\* -y
   > sudo apt-get install scylla
   > ```

Answer ‘y’ to the first two questions.

RHEL/CentOS

1. Remove the old repo file.
   > ```sh
   > sudo rm -rf /etc/yum.repos.d/scylla.repo
   > ```
2. Update the [ScyllaDB rpm repo](https://www.scylladb.com/download/?platform=centos&version=scylla-5.4)  to 5.4.
3. Install:
   > ```console
   > sudo yum clean all
   > sudo yum remove scylla\*
   > sudo yum install scylla
   > ```

#### NOTE
If you are running a ScyllaDB Enterprise official image (for EC2 AMI, GCP, or Azure), follow the instructions for Ubuntu.

### Restore the configuration file

```sh
sudo rm -rf /etc/scylla/scylla.yaml
sudo cp -a /etc/scylla/scylla.yaml.backup-src | /etc/scylla/scylla.yaml
```

### Restore system tables

Restore all tables of **system** and **system_schema** from the previous snapshot because
2024.1 uses a different set of system tables.
See [Restore from a Backup and Incremental Backup](https://opensource.docs.scylladb.com/stable/operating-scylla/procedures/backup-restore/restore.md)
for reference.

```console
cd /var/lib/scylla/data/keyspace_name/table_name-UUID/
sudo find . -maxdepth 1 -type f  -exec sudo rm -f "{}" +
cd /var/lib/scylla/data/keyspace_name/table_name-UUID/snapshots/<snapshot_name>/
sudo cp -r * /var/lib/scylla/data/keyspace_name/table_name-UUID/
sudo chown -R scylla:scylla /var/lib/scylla/data/keyspace_name/table_name-UUID/
```

### Reload systemd configuration

You must reload the unit file if the systemd unit file is changed.

```sh
sudo systemctl daemon-reload
```

### Start the node

```sh
sudo service scylla-server start
```

### Validate

Check the upgrade instructions above for validation. Once you are sure the node rollback
is successful, move to the next node in the cluster.
