DEV Community

Berislav Babic
Berislav Babic

Posted on • Originally published at berislavbabic.com

How to migrate your Redis database from one cloud provider to another

I've been doing a migration of our whole infrastructure from AWS to Azure recently. One of the services we use is Redis, which we use for caching purposes and to send our background jobs to Sidekiq. Since I don't care much about the cache part, I don't want to migrate it. But we kinda do care about the background jobs being scheduled because we are killing the source Redis endpoint.

We did use the Database Migration Service (both AWS and Azure have it, we used the Azure one since we are on Azure now) to migrate the Postgres database, which I'll be touching on in another post. But the DMS doesn't support Redis which meant I was SOOL on that front.

There is an option of backing up the whole Redis server into an rdb file and then restoring that file in Azure, but since the database would include cache data, and the backup takes longer than I want the site to be in maintenance mode, I went looking for a more elegant solution.

And the solution arrived packed into an npm package. Redis dump npm package allow you to dump the redis database of choice into SET commands txt format. The text format is acceptable as input to redis-cli which means you can import the Redis data pretty fast. This even allows you to import the data into a different Redis database, which wouldn't be an option with above mentioned rdb dump.

Using the tool is pretty straightforward, you first have to install the redis-dump npm package with npm install redis-dump -g. After that you run the command with your Redis server configuration, and it outputs the set commands into STDOUT.

redis-dump -h some-redis-host -p 6379 -d 7 -p REDIS_PASSWORD > redis_db.txt
Enter fullscreen mode Exit fullscreen mode

This command will output the contents of your Redis database as Redis SET commands, which you can load into the redis-cli binary directly. To import the backup you have to run cat redis_db.txt | redis-cli _target_redis_connection_options_.

Top comments (4)

Collapse
 
lem01 profile image
Laurent Lemaire

That's interesting! I wasn't aware of this NPM package and will give it a try.
We manage our Redis backup using redis-cli and save.

Collapse
 
umairhussain profile image
Umair Hussain Siddiqui

A very productive read! Thanks for sharing. I've been recently dive into this Cloud platform and eventually found it great. While surfying for php redis extension, I get to know that If you are using any PHP framework or any PHP-based CMS, many php redis extensions and plugins help you connect Redis with your framework.

Collapse
 
ajeetraina profile image
Ajeet Singh Raina

Have you looked at RIOT tool? developer.redis.com/explore/riot/

Collapse
 
berislavbabic profile image
Berislav Babic • Edited

No I haven't. I only needed this approach once when we were migrating from AWS to Azure. Now I'm on another project and luckily back on AWS. Thanks for the heads up.