Migrating a database from a third-party Valkey™ cluster
For data migration, Valkey™ uses a logical dump. A logical dump is a file with a sequence of commands that restore the database state. There are several ways to create a dump. The following example will use redis-dump-go
Note
You cannot use a binary RDB dump for migration, as Yandex Managed Service for Valkey™ does not provide access to the file system on cluster hosts.
To migrate Valkey™ databases from the source cluster to the target cluster:
-
Optionally, upload the dump to the intermediate VM.
You need to use a VM in Yandex Compute Cloud to transfer data if:
- Your Yandex Managed Service for Valkey™ cluster is not accessible from the internet.
- Your local hardware or Yandex Cloud cluster connection is not reliable enough.
If you no longer need the resources you created, delete them.
Required paid resources
The support cost for this solution includes:
- Yandex Managed Service for Valkey™ target cluster fee, which covers the use of computing resources allocated to hosts, and disk space (see Valkey™ pricing).
- Fee for using public IP addresses if public access is enabled for cluster hosts (see Virtual Private Cloud pricing).
- When creating a VM for dump upload: fee for the use of computing resources, storage, operating system (for certain OS types), and optionally public IP address (see Compute Cloud pricing).
Getting started
Set up your infrastructure
-
Create a Yandex Managed Service for Valkey™ cluster with any suitable configuration. To connect to the cluster from your local machine outside Yandex Cloud, enable TLS and public access for cluster hosts when creating the cluster.
-
Optionally, create an intermediate Linux VM in Yandex Compute Cloud in the same network as the Yandex Managed Service for Valkey™ cluster using the following configuration:
-
Under Boot disk image, select Ubuntu 20.04.
-
Under Network settings:
- Public IP address:
Auto. - Internal IPv4 address:
Auto. - Security groups: Same as for the Yandex Managed Service for Valkey™ cluster.
- Public IP address:
-
-
If using Virtual Private Cloud security groups, configure them.
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the configuration file matching your cluster type to the same working directory:
- redis-cluster-non-sharded.tf
: For a non-sharded cluster. - redis-cluster-sharded.tf
: For a sharded cluster.
Each file describes the following:
- Network.
- Subnet.
- Default security group and rules for connecting to your cluster and VM.
- Yandex Managed Service for Valkey™ cluster with public internet access.
- VM with public internet access, if required.
- redis-cluster-non-sharded.tf
-
Specify the following in the configuration file:
-
Password to access the Yandex Managed Service for Valkey™ cluster.
-
Optionally, VM settings:
- VM public image ID, e.g., for Ubuntu 20.04 LTS.
- Username and absolute path to the public SSH key for accessing the virtual machine. By default, Ubuntu 20.04 LTS ignores the specified username and automatically creates a user named
ubuntu. Use it to connect to the VM.
-
-
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
Install additional software
-
Optionally, install SSH file transfer tools on your local machine, such as the following:
-
Make sure GNU Screen
is installed on the source cluster.Creating and restoring a dump may take a long time. To keep these processes running when your SSH session times out, start them with this tool. If your SSH connection drops during these operations, reconnect and resume the session using this command:
screen -R
Connect to the source cluster and create a logical dump
-
Connect to the source cluster master host over SSH.
-
Download the archive with
redis-dump-gofrom the project page . The examples below use version0.5.1.wget https://github.com/yannh/redis-dump-go/releases/download/v0.5.1/redis-dump-go_0.5.1_linux_amd64.tar.gz -
Unpack the archive to the current directory:
tar xf redis-dump-go_0.5.1_linux_amd64.tar.gz -
Review the tool’s command-line options:
./redis-dump-go -h -
If connecting to the Valkey™ cluster requires a password, enter it in the
REDISDUMPGO_AUTHenvironment variable:export REDISDUMPGO_AUTH="<Valkey™_password>" -
Start an interactive
screensession:screen -
Start creating a logical dump:
./redis-dump-go \ -host <master_host_IP_address_or_FQDN_in_Valkey™_cluster> \ -port <Valkey™_port> > <dump_file>Tip
While the dump is being created, the number of processed keys will appear on the screen. Remember or write down the last output value, as you will need it to check whether the dump has been fully restored in the target cluster.
-
Once the dump is created, download it to your computer.
-
Terminate the interactive
screensession:exit
Optionally, upload the dump to the intermediate VM
-
Upload the dump from your computer to the intermediate VM in any way you like.
Restore the dump in the target cluster
-
Connect to the cluster and run an interactive
screensession:screen -
Start the dump recovery:
Connecting without TLSConnecting with TLSBefore connecting, install the required dependencies:
sudo apt update && sudo apt install -y redis-toolsConnecting via Sentinel
host=$(redis-cli \ -h <FQDN_of_any_Valkey™_host> \ -p 26379 \ sentinel \ get-master-addr-by-name \ no-shards-no-tls | head -n 1) redis-cli \ -h ${host} \ -p 6379 \ -a <target_cluster_password> \ --pipe < <dump_file>Connecting directly to the master host
redis-cli \ -h <master_host_FQDN> \ -p 6379 \ -a <target_cluster_password> \ --pipe < <dump_file>When connecting to a non-sharded cluster, you can use special FQDNs instead of the master host FQDN.
Connecting to a sharded cluster
-
Create a script with commands to load the dump:
load-dump.shshards=('<FQDN_of_master_host_in_shard_1>' \ ... '<FQDN_of_master_host_in_shard_N>') for shard in "${shards[@]}" ; do redis-cli -h "${shard}" \ -p 6379 \ -a "<target_cluster_password>" \ --pipe < <dump_file> done -
Run the script:
bash ./load-dump.shWhile the script runs, you may see data insertion error messages. This is normal behavior for the
redis-clicommand, as each shard in a sharded cluster stores only a portion of the data. For more information, see Sharding in Yandex Managed Service for Valkey™.
Before connecting, install the required dependencies:
Build
redis-toolswith TLS support using one of the two methods:-
From a repository
-
Add a repository:
sudo apt-add-repository ppa:redislabs/redisThe repository’s packages come pre-built with
BUILD_TLS=yes. -
Install the tool:
sudo apt update && sudo apt install -y redis-tools
-
-
Manually
Go to the directory you want to download the distribution to. Download the stable tool version, then build and install it:
wget https://download.redis.io/redis-stable.tar.gz && \ tar -xzvf redis-stable.tar.gz && \ cd redis-stable && \ make BUILD_TLS=yes && \ sudo make install && \ sudo cp ./src/redis-cli /usr/bin/
Connecting via Sentinel
host=$(redis-cli \ -h <FQDN_of_any_Valkey™_host> \ -p 26379 \ sentinel \ get-master-addr-by-name \ no-shards-tls | head -n 1) redis-cli \ -h ${host} \ -p 6380 \ -a <target_cluster_password> \ --tls \ --cacert ~/.redis/YandexInternalRootCA.crt \ --pipe < <dump_file>Connecting directly to the master host
redis-cli \ -h c-<cluster_ID>.rw.mdb.yandexcloud.net \ -p 6380 \ -a <target_cluster_password> \ --tls \ --cacert ~/.redis/YandexInternalRootCA.crt \ --pipe < <dump_file>When connecting to a non-sharded cluster, you can use special FQDNs instead of the master host FQDN.
Connecting to a sharded cluster
-
Create a script with commands to load the dump:
load-dump.shshards=('<FQDN_of_master_host_in_shard_1>' \ ... '<FQDN_of_master_host_in_shard_N>') for shard in "${shards[@]}" ; do redis-cli -h "${shard}" \ -p 6380 \ -a "<target_cluster_password>" \ --tls \ --cacert ~/.redis/YandexInternalRootCA.crt \ --pipe < <dump_file> done -
Run the script:
bash ./load-dump.shWhile the script runs, you may see data insertion error messages. This is normal behavior for the
redis-clicommand, as each shard in a sharded cluster stores only a portion of the data. For more information, see Sharding in Yandex Managed Service for Valkey™.
-
-
Terminate the interactive
screensession:exit
Make sure the dump is fully restored
- In the management console
, navigate to the folder where you want to restore the cluster. - In the list of services, select Yandex Managed Service for Valkey™.
- Click the cluster name and open the Monitoring tab.
Pay attention to the DB Keys chart showing the number of keys stored in the cluster. If the cluster is sharded, the chart will show the number of keys in each shard. In this case, the number of keys in the cluster is equal to the total number of keys across all shards.
The total number of keys in the cluster must match the number of keys processed by redis-dump-go when creating the dump.
Delete the resources you created
Delete the resources you no longer need to avoid paying for them:
- Delete the Yandex Managed Service for Valkey™ cluster.
- If you created a staging virtual machine, delete it.
- If you reserved public static IP addresses, release and delete them.
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy -
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-