Backup and restore
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.
Getting ready…
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.
How to do it...
Let us see how to backup and restore Redis data.
Backing up Redis data
Firstly, to back up Redis data, take the following steps:
- Execute the
BGSAVE
command on Redis Server:
$ bin/redis-cli BGSAVE Background saving started
- Copy the saved RDB file to a safe location:
$ cp /var/lib/redis/dump.rdb /mnt/backup/redis/dump.$(date +%Y%m%d%H%M).rdb