
Redis 4.x Cookbook

It is always important to have backup plans for production databases. Once things break, such as hard disk failure, accidental data deletion, or network intrusion, backing up the data can protect against data losses. In Chapter 6, Persistence, we have learned that Redis data can be persisted into the RDB file. In this recipe, we will revisit the RDB persistence option and show you the detailed steps you can take to back up and restore data for Redis.
You need to finish the installation of Redis Server, as we described in the Downloading and installing Redis recipe in Chapter 1, Getting Started with Redis.
Let us see how to backup and restore Redis data.
Firstly, to back up Redis data, take the following steps:
BGSAVE
command on Redis Server:$ bin/redis-cli BGSAVE Background saving started
$ cp /var/lib/redis/dump.rdb /mnt/backup/redis/dump.$(date +%Y%m%d%H%M).rdb