For databases where the appendonly flag is set to no, you can do the following:
- Stop Redis (because Redis overwrites the current rdb file when it exits).
- Copy your backup rdb file to the Redis working directory (this is the
diroption in your Redis config). Also, make sure your backup filename matches thedbfilenameconfig option. - Start Redis.
If, on the other hand, you need to restore an rdb file to the appendonly database, you should do something along the lines of:
- Stop Redis (because Redis overwrites the current rdb file when it exits).
- Copy your backup rdb file to the Redis working directory (this is the
diroption in your Redis config). Also, make sure your backup filename matches thedbfilenameconfig option. - Change the Redis config
appendonlyflag tono(otherwise Redis will ignore your rdb file when it starts). - Start Redis.
- Run
redis-cli BGREWRITEAOFto create a new appendonly file. - Restore the Redis config
appendonlyflag toyes.
Specifically, this is the relevant bit of documentation from the Redis config file comments:
# Note that you can have both the async dumps and the append only file if you
# like (you have to comment the "save" statements above to disable the dumps).
# >> Still if appendonly mode is enabled Redis will load the data from the
# >> log file at startup ignoring the dump.rdb file.