Avatar of Angelo SaracenoAngelo Saraceno

How to Backup Your Redis Instance

Redis is a popular choice for an in-memory data structure store that also persists to disk. For many projects it is used as a database, cache, and a message broker.
At Railway, you can provision and add Redis to your project in as easy as one-click. However, there comes a time when you need to perform a backup of your Redis instance. Recently, within our
Discord, we've had a couple of users ask us how they'd go about performing a backup of their Railway Project's Redis instance. This blog post will guide you on how to do just that.

Before we get started, you will need Redis installed locally. We are also assuming you are running this on a Unix based system (MacOS, Linux).

On one terminal instance, first run the following command. This will first start Redis locally on your machine.

redis-server

Then, on a different terminal instance, run the CLI to connect to the instance.

redis-cli

The reason why we set up a local Redis instance is because we are going to designate the local Redis instance to replicate the Railway plugin in your project.

In the Terminal that is running redis-cli enter the following command to enter the password of the Redis plugin.

config set masterauth <password>


You can get the password from your Railway project's variables and then clicking the Redis tab..

After you configure the password, you will need to start the replication process on your local instance by entering the following command in the terminal where redis-cli is running.

SLAVEOF <host> <port>

You can get the connection url under the plugin interface for your project.

After you perform that command, your local instance should begin replication. To see information about the replication status, you can enter the following in the terminal where redis-cli is running.

INFO replication

The output should look like the following

role:slave
master_host:RAILWAY_REDIS_URL
master_port:6519
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0

After INFO replication shows that there is no sync in progress when you see that the sync property is 0 like: master_sync_in_progress: 0. You are now ready to save locally what is on your local Redis instance.
You can do this by entering the following command in the
redis-cli

BGSAVE
CONFIG GET dir

The output of this command will tell you where in the system Redis saved the instance's data as a dump.rdb file. Now, you have your backup!

Before you stand down your instance, run the following in your redis-cli before you shut down redis-server. This is done so your Redis server won't attempt to sync with the Railway plugin any further.

SLAVEOF NO ONE

And with that, you should have all the information you need to backup your Redis instance on Railway! We at Railway are working to allow you to retrieve backups from the dashboard to make it easier to manage.

If you have any suggestions for more tutorials you'd like to see guides for, let us know on Discord.