How to use the RDB (Redis Backup File)

Backups are essential features in sensitive data environments such as databases. They allow us to perform restorations in case of failures and errors.

One example of such an environment is a database such as Redis. Since its an in-memory database, a simple error such as power failure can lead to data loss. It is therefore essential to have persistence for your data.

This tutorial will learn how to work with the Redis Database Backup to save the data stored in the memory to the system’s disk and perform restorations from the RDB.

Backing Up Data

We use the SAVE command to perform a backup of the current dataset in Redis. The command will create a snapshot containing all the data in the Redis cluster in the binary format of the dump.rdb file.

To use the SAVE command, type SAVE inside the Redis CLI.> SAVE

Once you execute the command, Redis should return a string, OK, indicating that no errors were encountered in the command.

If not, Redis will return an error message showing the error type in the command. For example, Redis will provide the following error for incorrect arguments.> SAVE 1
(error) ERR wrong number of arguments for 'save' command

Once the SAVE command is executed successfully, Redis will create a dump.rdb file in the Redis directory.

Redis does not recommend using the SAVE command in production. This is because it blocks other clients until the operation is completed.

To resolve this, you can use the BGSAVE command. It works similarly to the SAVE command but uses a child process in the background.

For example:> BGSAVE
Background saving started

Restoring Data

Backups serve no purpose if we cannot use them. Let us discuss how you can use the dump.rdb file to restore your datasets.

Start by noting the location of your backup dump.rbd file.

Next, stop the Redis server:

sudo service redis-server stop

Move the dump.rdp backup file into the root of Redis server

sudo mv ~/dump.rdb /var/lib/redis/

You should now have the data from the dump.rdb loaded into Redis.


This article taught us how to perform backup and restoration in Redis using the RDB dump file.

Stay tuned for more tutorials!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list