Redis RDB data backup and recovery

created at 07-24-2021 views: 24

Redis data backup


> redis-cli> bgsave

Here why use bgsave instead of save, please refer to the article:

Detailed explanation of redis persistence, what is RDB?

Redis restore data

1. Get the redis backup directory> CONFIG GET dir
1) "dir"
2) "D:\\software\\Redis">

The redis backup directory output by the above command CONFIG GET dir is /usr/local/redis/bin.

2. Stop the redis service

src/redis-cli -p 6379 shutdown

# Use kill command to close redis
kill -9 6379

src is the redis installation directory

3. Copy the redis backup file (dump.rdb) to the /usr/local/redis/bin directory

4. Restart the redis service


src/redis-server redis.conf

# ubuntu
/etc/init.d/redis-server stop
/etc/init.d/redis-server start
/etc/init.d/redis-server restart

ubuntu (where is the backup file, start redis there)

redis-server xx.conf

xx.conf is the redis configuration file> config get dir
1) "dir"
2) "/var/lib/redis"

cd /var/lib/redis
redis-server xx.conf



In fact, as long as redis restarts, it will automatically read the dump.rdb file in the backup directory. If there is this file, it will automatically restore the data.

5. Check if redis recovers data

$ src/redis-cli> keys *
 1) "k1"
 2) "k2"
 3) "k3"
 4) "k4"
 5) "k5"
created at:07-24-2021
edited at: 07-24-2021: