Migrating and Backing up with ApsaraDB for Redis

Setting up the Backup File

ApsaraDB for Redis allows you to migrate with the EOF file. Make sure you set appendonly on your Redis database with the following command:

config set appendonly yes

Creating an Alibaba Cloud ECS Instance

Now, let’s setup Redis on Alibaba Cloud’s ApsaraDB for Redis. To do this, we will have to first create an Alibaba Cloud ECS Instance on which you will then attach the Redis service. Let’s create an ECS instance installed with Ubuntu 16.04. Choose the region based on your requirements.

Setting up the Instance and Redis

Now, let’s install everything we need on the instance. First, we need to do the required Ubuntu updates:

apt-get update
apt-get upgrade
apt-get dist-upgrade
apt install redis-tools

Creating an ApsaraDB for Redis Instance

Now you can create an ApsaraDB for Redis instance that is connected to the default VPC and ECS which we just created.

Connecting to ApsaraDB Redis

Now let’s connect to the ApsaraDB for Redis instance on the ECS instance we have just created. We will use the SSH protocol for this.

redis-cli -h [Connection Address] -a [password]

Getting ApsaraDB for Redis Ready for Migration

Follow these steps to make sure that your installation is in proper working order. To do this, you’ll need to follow these steps:

Migrating Redis to Alibaba Cloud

In a terminal window, cd to the local directory in which your appendonly.aof file resides and run the following scp command:

scp appendonly.aof root@47.90.244.142:/home
redis-cli -h [Connection Address] -p 6379 -a [password] --pipe < appendonly.aof

Connecting with Jedis

You can also connect to your Alibaba Cloud ApsaraDB for Redis instance with Jedis for Java in Eclipse. Before you can access the Redis instance in the cloud you have to open some ports with network configuration changes on the ECS instance.

wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xvf rinetd.tar.gz&&cd rinetd
sed -i 's/65536/65535/g' rinetd.c
mkdir /usr/man&&make&&make install
nano /etc/rinetd.conf
0.0.0.0 6379 r-7go1a73cf051c984.redis.rds.aliyuncs.com 6379
logfile /var/log/rinetd.log
rinetd

Setting up Backup Configurations

As with all the other Alibaba Cloud ApsaraDB services, in the ApsaraDB for Redis instance details, you can set backup configurations for your Redis instance.

Summary

To summarize what we did in this tutorial, we first had set up our Redis database and made sure it was working, and we set an example key-value pair. Then, we made sure we saved our local Redis database with the appendonly option. Next, after that, we created an Alibaba Cloud ECS Instance on which to host our ApsaraDB for Redis instance. We configured the instance to have Ubuntu 16.04 as our operating system and setup Redis on the instance. Next, we created an Alibaba Cloud ApsaraDB for Redis instance, which was attached to the ECS instance we had just created. We migrated our local database to the Alibaba Cloud instance and checked whether it had migrated successfully. Finally, we performed some network administration in order to be able to access our Alibaba Cloud ApsaraDB for Redis instance from outside the cloud console. We chose the Java Jedis client and wrote a test class to check that we could connect to the cloud database.

Original Source:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store