Dragonfly

How to Create and Restore a Backup in Redis?

In this guide, we will explore how to create and restore a backup in Redis by demonstrating concepts and hands-on code examples.

July 18, 2025

Running Redis in Docker: A Practical Guide

Redis provides the functionality to create and restore backups of your database. Let's see how you can do it.

Creating a Backup

For creating a backup, Redis uses the SAVE or BGSAVE commands. The SAVE command operates synchronously but will block other operations until it has completed. On the other hand, BGSAVE performs the backup process in the background. Here is an example:

redis$> BGSAVE

After running this command, a dump file named dump.rdb will be created in your Redis directory.

Restoring a Backup

Restoring a backup in Redis is quite simple as well. It involves just moving your backup file (dump.rdb) to the proper Redis directory and starting your server. Redis automatically loads the dump.rdb file on startup.

To find the default directory where Redis looks for the dump.rdb file, you can check your Redis configuration file (usually named redis.conf). Look for the line that starts with dir.

Here's how you can find and set the correct path:

  • Open your Redis configuration file:
$> nano /etc/redis/redis.conf
  • Locate the dir configuration. It should look something like this:
# In the redis.conf file.
dbfilename dump.rdb
dir /var/lib/redis
  • Use the path specified in the dir line for the following steps.
  • Note that by default, the backup file is named dump.rdb, but you can also change it by using the dbfilename directive in redis.conf.

Here is a simple example of restoring a backup:

  • First, stop your Redis server:
redis$> SHUTDOWN
  • Then, move your backup file to the Redis directory found in the configuration:
$> mv /path/to/your/dump.rdb /path/to/redis/dir/
  • Finally, start your Redis server again:
$> redis-server

Please note, the paths /path/to/your/ and /path/to/redis/dir/ need to be replaced with actual paths in your system that you found in the redis.conf file.

In conclusion, Redis makes it easy to create backups using the SAVE or BGSAVE commands and restore them by simply moving the backup file to the correct directory and restarting the server. Be sure to always back up your data regularly and verify your backups for data reliability.

Was this content helpful?

Help us improve by giving us your feedback.

Dragonfly Wings

Stay up to date on all things Dragonfly

Join our community for unparalleled support and insights

Join

Switch & save up to 80%

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost