How to Migrate Redis™ Data Using Redis-Shake 
Tags: redis, database, developer
Published: 2021-11-26 21:26:51

---
title: How to Migrate Redis™ Data Using Redis-Shake 
published: true
description: Need to migrate your Redis data? Redis-Shake makes it easy for you to move your data or split it between different servers. Check out this simple guide!
tags: redis, database, developer
cover_image: https://scalegrid.io/blog/wp-content/uploads/2021/11/Redis-Shake-Guide-Blog.jpg
---
<link rel="canonical" href="https://scalegrid.io/blog/how-to-migrate-redis-data-using-redis-shake/" />
<p style="text-align: justify;">Migrating ScaleGrid for Redis™* data from one server to another is a common requirement that we hear from our customers. Two of the main reasons we hear are often due to migration of hardware, or the need to split data between servers.</p>
<p style="text-align: justify;">Typically, you want to migrate with minimal downtime while using the standard Redis tools. In this blog post, we will guide you through the process using the open-source tool <a style="color: #2da964; text-decoration: underline;" href="https://github.com/alibaba/RedisShake">Redis-Shake</a>. Developed and maintained by the NoSQL Team in the Alibaba-Cloud Database department, <a style="color: #2da964; text-decoration: underline;" href="https://scalegrid.io/blog/how-to-migrate-redis-data-using-redis-shake/">Redis-Shake allows you to easily migrate Redis data between Redis clusters</a>. While this guide is more aimed towards ScaleGrid for Redis™* deployments, this guide can be used for other types of Redis deployments as well with some slight modifications.</p>

<p style="text-align: justify;">Without further ado, let’s get started with the migration guide!</p>

<h2 style="padding-bottom: 10px;">Prerequisites</h2>
<p style="text-align: justify;">You’ll need a Linux or Windows machine to perform the migration. (If needed, this can be either the source or the target machines).</p>

<p style="text-align: justify;">An important thing to make sure of before you continue is that Redis-Shake does not support SSL-enabled clusters as of now. Please make sure that both the source and the target clusters are not SSL-enabled.</p>

<h2 style="padding-bottom: 10px;">Firewall Rule</h2>
<p style="text-align: justify;">Make sure you have created a firewall rule in order to allow your Linux/Windows machine to connect to both your source and target clusters. Refer to this <a style="color: #2da964; text-decoration: underline;" href="https://help.scalegrid.io/docs/redis-cluster-operations-firewall-rules">link</a> for more info on how to set this up on ScaleGrid.</p>

<h2 style="padding-bottom: 10px;">Download Redis-Shake </h2>
<p style="text-align: justify;">Download and decompress Redis-Shake on the Linux/Windows machine after choosing the latest/stable version from this <a style="color: #2da964; text-decoration: underline;" href="https://github.com/alibaba/RedisShake/releases">link</a>. You can also use the following commands below to download the latest version as of today (v2.1.1).</p>
<code>
wget https://github.com/alibaba/RedisShake/releases/download/release-v2.1.1-20210903/release-v2.1.1-20210903.tar.gz
tar -xvzf release-v2.1.1-20210903.tar.gz
cd release-v2.1.1-20210903/
</code>
<p style="text-align: justify;">Next up, we will show you two different use cases for Redis-Shake.</p>
<ul>
<li><a style="color: #2da964; text-decoration: underline;" href="#1">Migrating data from a Standalone and Master-Slave</a></li>
<li><a style="color: #2da964; text-decoration: underline;" href="#2">Migrating data in Cluster Mode</a></li>
</ul>

<h2 style="padding-bottom: 10px;"><a id="1"></a>Migrating Data - Standalone and Master-Slave</h2>
<p style="text-align: justify;">In this section, we will show you how to migrate your data in these different setups:</p>
<ul>
<li>Standalone to Standalone</li>
<li>Master-Slave to Master-Slave</li>
<li>Standalone to Master-Slave (and vice-versa)</li>
</ul>

<h4>1. Gather info</h4>
<p style="text-align: justify;">Note down the following info from the Overview tab in the cluster details page from both your source and target cluster:</p>
<ul>
<li><strong>Hostname</strong>: The Connection String is in the format [hostname:port]. It should look something like this: <em>EX-redms-00-redis-master.example.domain.io</em></li>
<ul>
<li>(In the case of a Master-Slave cluster, we’ll connect to the master).</li>
</ul>
<li><strong>Port</strong>: 6379</li>
<li><strong>Password</strong>: You can find your password and reset it from the console under Credentials</li>
</ul>
<h4>2. Edit Config File</h4>
<p style="text-align: justify;">Open your “redis-shake.conf” file in the main folder and edit the following variables:</p>
<code>source.type = <strong>standalone</strong>
source.address = <strong>&#60;source_hostname&#62;:6379</strong>
source.password_raw = <strong>&#60;source_password&#62;</strong></code>

<code>target.type = <strong>standalone</strong>
target.address = <strong>&#60;target_hostname&#62;:6379</strong>
target.password_raw = <strong>&#60;target_password&#62;</strong></code>

<h4>3. Sync Data</h4>
<p style="text-align: justify;">Run the following command to synchronize data between the source and target cluster:</p>
<code>$ ./redis-shake -type sync -conf redis-shake.conf</code>
<h4>4. Wait For Logs</h4>
<p style="text-align: justify;">Wait until you see the following information in the logs:</p>
<code>sync rdb done.</code>
<p style="text-align: justify;">This means that the full synchronization has been completed and incremental synchronization begins.</p>
<h4>5. Stop Incremental Sync</h4>
<p style="text-align: justify;">If <code>+writeBytes=0</code> is seen for a long time, then that means no new data is incremented. You can stop the incremental synchronization by pressing <strong>Ctrl+C</strong>. It should look like something like this:</p>
<code>sync:  +forwardCommands=0  +filterCommands=0  +writeBytes=0</code>
<h4>6. Match Number of Keys</h4>
<p style="text-align: justify;">Now follow this <a style="color: #2da964; text-decoration: underline;" href="https://help.scalegrid.io/docs/connect-redis-via-command-line">link</a> to our help doc which helps you connect to both clusters using redis-cli and then match the number of keys between your clusters using the <code>info keyspace</code> command on both clusters.</p>
<p style="text-align: justify;">And that’s it! You’ve now successfully migrated data from one cluster to another using Redis-Shake. If you have clusters in Cluster Mode, you might want to have a look at our next section in this guide to see what you need to do if you're running that type of cluster.</p>

<h2 style="padding-bottom: 10px;"><a id="2"></a>Migrating Data - Cluster Mode</h2>
<p style="text-align: justify;">In this section, we will show you how to migrate data from one Redis deployment in cluster mode to another cluster.</p>
<h4>1. Gather info</h4>
<p style="text-align: justify;">Note down the following info from the Overview tab in the cluster details page from both your source and target cluster:</p>
<ul>
<li><strong>Hostname</strong>: The Connection String is in the format [hostname1:port], [hostname2:port], [hostname3:port]. It should look something like this: <em>EX-redms-03-redis-master.example.domain.io, EX-redms-06-redis-master.example.domain.io, EX-redms-09-redis-master.example.domain.io</em>
<li><strong>Port</strong>: 6379</li>
<li><strong>Password</strong>: You can find your password and reset it from the console under Credentials</li>
</ul>
<h4>2. Edit Config File</h4>
<p style="text-align: justify;">Open your “redis-shake.conf” file in the main folder and edit the following variables:</p>
<code>source.type = <strong>cluster</strong>
source.address = <strong>&#60;source_hostname1&#62;:6379;&#60;source_hostname2&#62;:6379;&#60;source_hostname3&#62;:6379</strong>
source.password_raw = <strong>&#60;source_password&#62;</strong></code>

<code>target.type = <strong>standalone</strong>
target.address = <strong>&#60;target_hostname1&#62;:6379;&#60;target_hostname2&#62;:6379;&#60;target_hostname3&#62;:6379</strong>
target.password_raw = <strong>&#60;target_password&#62;</strong></code>

<h4>3. Sync Data</h4>
<p style="text-align: justify;">Run the following command to synchronize data between the source and target cluster:</p>
<code>$ ./redis-shake -type sync -conf redis-shake.conf</code>
<h4>4. Wait For Logs</h4>
<p style="text-align: justify;">Wait until you see the following information in the logs:</p>
<code>sync rdb done.</code>
<p style="text-align: justify;">This means that the full synchronization has been completed and incremental synchronization begins.</p>
<h4>5. Stop Incremental Sync</h4>
<p style="text-align: justify;">If <code>+writeBytes=0</code> is seen for a long time, then that means no new data is incremented. You can stop the incremental synchronization by pressing <strong>Ctrl+C</strong>. It should look like something like this:</p>
<code>sync:  +forwardCommands=0  +filterCommands=0  +writeBytes=0</code>
<h4>6. Match Number of Keys</h4>
<p style="text-align: justify;">Now follow this <a style="color: #2da964; text-decoration: underline;" href="https://help.scalegrid.io/docs/connect-redis-via-command-line">link</a> to our help doc which helps you connect to both clusters using redis-cli and then match the number of keys between your clusters using the <code>info keyspace</code> command on both clusters.</p>
<p style="text-align: justify;">And that’s it! You’ve now successfully migrated data from one cluster in Cluster Mode to another using Redis-Shake. For more info on Redis-Shake and its capabilities, visit their <a style="color: #2da964; text-decoration: underline;" href="https://github.com/alibaba/RedisShake">GitHub page</a> to find out more and get the latest version.</p>
<p style="font-size: 10pt;">*Redis is a trademark of Redis Labs Ltd. Any rights therein are reserved to Redis Labs Ltd. Any use by ScaleGrid is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and ScaleGrid.</p>