Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover redis data from snapshot(rdb file) copied from another machine?

Tags:

redis

snapshot

I transferred my redis snapshot (dump.rdb file) using scp to a remote server. I need to run a redis server on this remote and recover the data from the dump.rdb file. How can I do that?

like image 460
hupantingxue Avatar asked Jan 24 '13 08:01

hupantingxue


People also ask

How do I restore an RDB file?

To restore redis data just move redis backup file (dump. rdb) into your redis directory and start the server. To get your redis directory use CONFIG command can be used. The CONFIG GET command is used to read the configuration parameters of a running Redis server.

Where are Redis snapshots stored?

Snapshotting. By default Redis saves snapshots of the dataset on disk, in a binary file called dump. rdb . You can configure Redis to have it save the dataset every N seconds if there are at least M changes in the dataset, or you can manually call the SAVE or BGSAVE commands.

What is Redis snapshot?

In Redis, a snapshot refers to the process and method of ensuring the persistence of data from the system memory to a permanent location such as the system's disk. Although Redis is an in-memory data store, it does provide various methods to store and recover data to and from the system's disk.


2 Answers

There is nothing specific to do. Just install the redis server on the new machine, and edit the configuration file. You just need to change the following parameters to point to the location of the dump file you have just copied.

# The filename where to dump the DB dbfilename mydump.rdb  # The working directory. # # The DB will be written inside this directory, with the filename specified # above using the 'dbfilename' configuration directive. #  # Also the Append Only File will be created inside this directory. #  # Note that you must specify a directory here, not a file name. dir /data/mydirectory/ 

Finally, the redis server can be started in the normal way.

like image 97
Didier Spezia Avatar answered Sep 21 '22 06:09

Didier Spezia


For databases where the appendonly flag is set to no, you can do the following:

  1. Stop redis (because redis overwrites the current rdb file when it exits).
  2. Copy you backup rdb file to the redis working directory (this is the dir option in your redis config). Also make sure your backup filename matches the dbfilename config option.
  3. Start redis.

If, on the other hand, you need to restore a rdb file to an append only database, you should do something along the lines of:

  1. Stop redis (because redis overwrites the current rdb file when it exits).
  2. Copy your backup rdb file to the redis working directory (this is the dir option in your redis config). Also make sure your backup filename matches the dbfilename config option.
  3. Change the redis config appendonly flag to no (otherwise redis will ignore your rdb file when it starts).
  4. Start redis.
  5. Run redis-cli BGREWRITEAOF to create a new appendonly file.
  6. Restore redis config appendonly flag to yes.

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 append only mode is enabled Redis will load the data from the                                                           # >> log file at startup ignoring the dump.rdb file.  
like image 23
Robert Kajic Avatar answered Sep 22 '22 06:09

Robert Kajic